java new way to implement singleton, use enum

public enum Elvis {
       INSTANCE
;
       
private final String[] favoriteSongs =
           
{ "Hound Dog", "Heartbreak Hotel" };
       
public void printFavorites() {
           
System.out.println(Arrays.toString(favoriteSongs));
       
}
   
}

你可能感兴趣的:(Singleton)