Add java11-features module: runnable demos and captured output for the ankurm.com java11-features article
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
/** JEP 181: nest-based access. Private members of nest mates no longer need synthetic accessor methods. */
|
||||
public class NestMates {
|
||||
private int secret = 42;
|
||||
static class Inner { int peek(NestMates n) { return n.secret; } }
|
||||
public static void main(String[] args) {
|
||||
System.out.println("nest host : " + Inner.class.getNestHost().getSimpleName());
|
||||
System.out.println("inner can read : " + new Inner().peek(new NestMates()));
|
||||
long synthetic = java.util.Arrays.stream(NestMates.class.getDeclaredMethods()).filter(m -> m.getName().startsWith("access$")).count();
|
||||
System.out.println("access$ methods on outer: " + synthetic);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user