I’m writing an Android app and I have a class that generates and maintains some fixed URL’s that can occasionally change. I keep them all in one class called UrlUtils:
public class UrlUtils {
private static String sUrlBase = "http://google.com";
/**
* Called occasionally
*/
public static void refreshUrlBases() {
sUrlBase = "http://yahoo.com/" + new Random().nextInt();
}
public static String getUrlBase() {
return sUrlBase;
}
}
I have to make a lot of calls to getUrlBase() above, so I was thinking about making sUrlBase public and access it directly. Will this approach be better in terms of performance?
If you are not going to change your url more frequently, then instead of
getter/settermethod I will say that you can keepstaticdirectlyIn keeping
staticmethod, it may happen that due to some problemstaticsettervalues areremoved(reset to original). So, in that case it will return you theoriginalconstant ofstaticvalue.UPDATE:
If your are going to update your
URLdynamicallythenstaticmethodwould prove to be better option.