Created
December 3, 2010 15:24
-
-
Save mattnworb/727090 to your computer and use it in GitHub Desktop.
Testing claims made in http://stackoverflow.com/questions/4346521/what-are-the-dangers-in-upgrading-to-java-1-5-and-beyond/4346599#4346599
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Testing claims made in | |
* http://stackoverflow.com/questions/4346521/what-are-the | |
* -dangers-in-upgrading-to-java-1-5-and-beyond/4346599#4346599 | |
* | |
* @date Dec 3, 2010 | |
*/ | |
public class ClassLoadingTest { | |
public static void main(String[] args) { | |
OldStyleEnum ose = null; | |
String test = "test"; | |
System.out.println("null OldStyleEnum == \"test\"? " + ((Object) ose == (Object) test)); | |
System.out.println("OldStyleEnum.ONE == OldStyleEnum.ONE? " + (OldStyleEnum.ONE == OldStyleEnum.ONE)); | |
System.out.println("OldStyleEnum.ONE == OldStyleEnum.TWO? " + (OldStyleEnum.ONE == OldStyleEnum.TWO)); | |
} | |
} | |
public class OldStyleEnum { | |
static { | |
System.out.println("OldStyleEnum static initializer run"); | |
} | |
public static final OldStyleEnum ONE = new OldStyleEnum("ONE"); | |
public static final OldStyleEnum TWO = new OldStyleEnum("TWO"); | |
private String value; | |
private OldStyleEnum(String value) { | |
this.value = value; | |
} | |
public String getValue() { | |
return value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code outputs the following on a 1.6 JVM: