In getInstance () of java.util.Calendar, It is not a singleton object acquisition method.
Calendar calendar = Calendar.getInstance();
Will create a new instance.
So it's okay to keep it in the field. The inside is not rewritten without knowing it.
However, it's too disgusting, so maybe I should try it like this.
public class CalendarFactory {
public static Calendar createInstance() {
// WARN:
//GetInstance below()Creates a new instance.
return Calendar.getInstance();
}
}
...
Calendar calendar = CalendarFactory.createInstance();
Is it really part of the standard SDK? It's freedom.
reference: https://stackoverflow.com/questions/6055112/why-can-i-have-only-one-instance-of-calendar-object?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
Recommended Posts