Skip to content

Commit 81a5fab

Browse files
committed
Ejemplo de singleton generico
1 parent 4acaf60 commit 81a5fab

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
public class simonguzman {
2+
public static void main(String[] args) {
3+
genericSingleton();
4+
}
5+
6+
public static void genericSingleton(){
7+
Singleton singleton = Singleton.getInstance();
8+
singleton.showMessage();
9+
}
10+
11+
public static class Singleton{
12+
private static Singleton instance;
13+
14+
private Singleton(){
15+
16+
}
17+
18+
public static Singleton getInstance(){
19+
if(instance == null){
20+
instance = new Singleton();
21+
}
22+
return instance;
23+
}
24+
25+
public static void showMessage(){
26+
System.out.println("Soy un Singleton.");
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)