Singleton Pattern
Only one instance is created
</ font>
This page describes the following ・ Singleton Pattern sample code
Check with the following class structure
class | Explanation |
---|---|
singleton.class | Create only one instance |
user(Main.class) | Create an instance |
singleton.class
class singleton{
private static singleton singleton = new singleton();
private singleton(){}
public static singleton newInstance(){return singleton;}
}
user(Main.class)
public static void main(String[] args){
singleton s1 =singleton.newInstance();
}}
Recommended Posts