How to make a singleton for retrofit 2?
问题 If there exists multiple retrofit call, how can i make a singleton of a retrofit, so that there won't be repeated codes within the class, thereby get rid of unnecessary codes. 回答1: Here's an example, but! Although this might be shiny and easy to use, singletons are evil. Try to avoid using them if possible. One way around it is by using dependency injection instead. Anyway. public class Api { private static Api instance = null; public static final String BASE_URL = "your_base_url"; // Keep