Changed module name. (#13098)
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.serializable_singleton;
|
||||
|
||||
public enum EnumSingleton {
|
||||
|
||||
INSTANCE("State Zero");
|
||||
|
||||
private String state;
|
||||
|
||||
private EnumSingleton(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public static EnumSingleton getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public String getState() { return this.state; }
|
||||
|
||||
public void setState(String state) { this.state = state; }
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.baeldung.serializable_singleton;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Singleton implements Serializable {
|
||||
|
||||
private static Singleton INSTANCE;
|
||||
private String state = "State Zero";
|
||||
|
||||
private Singleton() {
|
||||
}
|
||||
|
||||
public static Singleton getInstance() {
|
||||
if(INSTANCE == null) {
|
||||
INSTANCE = new Singleton();
|
||||
}
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user