I am very confused. I found many implementations of the Singleton design pattern in java. One of the found implementations is as follows:
public class MySingleton {
private static class Loader {
static MySingleton INSTANCE = new MySingleton();
}
private MySingleton () {}
public static MySingleton getInstance() {
return Loader.INSTANCE;
}
}
as described here: qaru.site/questions/65513 / ... . Now, if this implementation should work, why not the following?
public class MySingleton {
private static final MySingleton INSTANCE = new MySingleton();
private MySingleton () {}
public static MySingleton getInstance() {
return INSTANCE;
}
}
, java , , , .
: qaru.site/questions/23102/..., , , , singleton , INSTANCE (getInstance).
, : , singleton?