Can I let a static field of a class keep a reference to an instance of itself? If so, will it keep alive in the jvm without anyone else keeping a reference?
public class StatTest {
private static StatTest statTest;
public static StatTest getStatTest () {
if (statTest== null) {
statTest= new StatTest ();
statTest.init();
}
return statTest;
}
private StatTest() { }
}
Yes, This is the concept of the Singleton design pattern!