开发者

It is related to core java enums

开发者 https://www.devze.com 2022-12-27 20:16 出处:网络
what is singleton instances of the enumer开发者_如何学JAVAation class in java?Perhaps you\'re talking aobut using an enum to implement the singleton pattern?

what is singleton instances of the enumer开发者_如何学JAVAation class in java?


Perhaps you're talking aobut using an enum to implement the singleton pattern?

public enum Singleton {
   INSTANCE;
   public void singletonMethod() { ... }
}

Since enums were added to Java, this is the best (shortest, most correct) way to implement singletons.

0

精彩评论

暂无评论...
验证码 换一张
取 消