Java: Out with the Old, In with the New

后端 未结 30 2082
遥遥无期
遥遥无期 2020-12-22 16:11

Java is nearing version 7. It occurs to me that there must be plenty of textbooks and training manuals kicking around that teach methods based on older versions of Java, whe

30条回答
  •  情书的邮戳
    2020-12-22 16:42

    Improved singleton patterns. Technically these are covered under the popular answer enums, but it's a significant subcategory.

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

    is cleaner and safer than

    public class Singleton {
        public static final Singleton INSTANCE = new Singleton();
    
        private Singleton() {
            ...
        }
    
        public void someMethod() {
            ...
        }
    }
    

提交回复
热议问题