Class A 1
public class A {
private static final A instance = new A();
public static A getInstance() {
return new A();
}
}
Class A 2
public class A {
private static final A instance = new A();
private A(){}
public static A getInstance() {
return instance;
}
}
I just start to learn singleton and I saw two java examples that using class A 1 example and class A 2 example. Is the class A 1 getInstance()
is singleton? I also like to know what is the differences between these two class A getInstance()
method? Thank you