Is the following code resistant to both Serialization and Reflection Attacks?
public class Example{ private static Example instance=new Example(); private E
No, it is not. There is a better technique.
Try something like this:
public enum Elvis { INSTANCE; public static boolean isThereOnlyOneElvis() { return true; } } // In your code: if ( !Elvis.INSTANCE.isThereOnlyOneElvis() ) { System.err.println("Liar !!!"); }