Last active
August 29, 2015 14:00
-
-
Save retronym/78db763886ebfd55df02 to your computer and use it in GitHub Desktop.
JVM value classes, interfaces, and defaults
This file contains 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
// http://cr.openjdk.java.net/~jrose/values/values-0.html | |
// | |
// Can a value class implement interfaces? Yes. Boxing may occur when we treat a value as an interface instance. | |
// | |
// ... | |
// | |
// Since values do not have identity, there are certain operations that are | |
// identity-specific and either need to be disallowed on values or assigned a | |
// new meaning for use in the context of values. | |
// | |
// * Locking. Using a value as the lock object of a synchronized statement, | |
// or calling the related methods wait and notify, should be disallowed. | |
public class test { | |
static interface Default { | |
default public void foo() { | |
synchronized(this) { | |
System.out.println("Default.foo"); | |
} | |
} | |
} | |
static /*value*/ class Meter implements Default { | |
public Double value; | |
} | |
new Meter().foo() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment