Skip to content

Instantly share code, notes, and snippets.

@mattnworb
Created December 3, 2010 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattnworb/727090 to your computer and use it in GitHub Desktop.
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
*
* @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;
}
}
@mattnworb
Copy link
Author

This code outputs the following on a 1.6 JVM:

null OldStyleEnum == "test"? false
OldStyleEnum static initializer run
OldStyleEnum.ONE == OldStyleEnum.ONE? true
OldStyleEnum.ONE == OldStyleEnum.TWO? false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment