Skip to content

Instantly share code, notes, and snippets.

@retronym
Last active August 29, 2015 14:00
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 retronym/78db763886ebfd55df02 to your computer and use it in GitHub Desktop.
Save retronym/78db763886ebfd55df02 to your computer and use it in GitHub Desktop.
JVM value classes, interfaces, and defaults
// 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