Add java11-features module: runnable demos and captured output for the ankurm.com java11-features article

This commit is contained in:
2026-10-20 17:13:58 +00:00
parent 77c782abbf
commit 8b9447a393
19 changed files with 223 additions and 0 deletions
+13
View File
@@ -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);
}
}