Java Calendar is not a singleton.

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

Java Calendar is not a singleton.
What is a Java collection?
What is a lambda expression (Java)
Why Java Vector is not used
What is a class in Java language (3 /?)
How to make a Java calendar Summary
What is a class in Java language (1 /?)
What is a class in Java language (2 /?)
What is java
[Java] Singleton pattern
What is Java <>?
GetInstance () from a @Singleton class in Groovy from Java
Eclipse does not start after Java 11 is installed
java.util.Arrays.asList () is not a replacement for new ArrayList <> ()
Cause of is not visible when calling a method of another class in java
[Java] Calculate the day of the week from the date (Calendar class is not used)
What is a constructor?
[Java] About Singleton Class
What is a stream
java build a triangle
What is Java Encapsulation?
Quickly implement a singleton with an enum in Java
Yarn is not installed
What is Java technology?
File path is not recognized when executing an external command from a Java application
[Java] What is flatMap?
What is a Servlet?
Java11: Run Java code in a single file as is
[Java] What is JavaBeans?
[Java] What is ArrayList?
Docker × Java Building a development environment that is too simple
[Android / Java] Creating a super-simple Option Menu (API not implemented)
[Java] A class is an OS, and an instance is a virtual computer.
[Java] final override error is not displayed at compile time
What is Java Assertion? Summary.
DateFormat is not thread safe
"tx" is not bound error
What is a wrapper class?
What is a boolean type?
What is a Ruby module?
What is a floating point?
What is a meaningful comment?
Ruby # {} is not variable expansion
Creating a calendar using Ruby
What is a jar file?
[Java] Create a temporary file
[Java] Make it a constant
[Windows] Java code is garbled
What is a lambda expression?
OkHttp3 should be a singleton
[Java] What is jaee j2ee?
[Java] What is class inheritance?
Java creates a Word document
What is a fa⁉ enum?
[Rails] fields_for is not displayed
Make a rhombus using Java
[Java basics] What is Class?
What is java escape analysis?
Java is the 5th day
[Java] List method that determines whether a specific object is included
Project facet Java version 13 is not supported. How to deal with