单例模式
Last updated
Last updated
@Data
public class Client {
private String name;
}public enum Single {
INSTANCE;
private Client client;
Single() {
this.client = new Client();
}
public Client getClient() {
return client;
}
}public class Test {
public static void main(String[] args) {
Client client = Single.INSTANCE.getClient();
Client client1 = Single.INSTANCE.getClient();
System.out.println(client == client1);
}
}