I want create singleton class But I don't know how?
Example:
class Singleton {
Singleton singleton = null;
public static Singleton getInstance()
{
if (singleton == null)
singleton = new Singleton();
return singleton;
}
}
Simply add static before in the singleton class.
class Singleton {
static Singleton singleton = null;
public static Singleton getInstance()
{
if (singleton == null)
singleton = new Singleton();
return singleton;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.