Skip to content

Instantly share code, notes, and snippets.

@metebalci
Created June 28, 2018 10:03
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 metebalci/ef92df99efc9b53278bb6f96c2240f77 to your computer and use it in GitHub Desktop.
Save metebalci/ef92df99efc9b53278bb6f96c2240f77 to your computer and use it in GitHub Desktop.
JEP181
import java.lang.reflect.Field;
public class JEP181 {
public static class Nest1 {
private int varNest1;
public void f() throws Exception {
final Nest2 nest2 = new Nest2();
// this is ok
nest2.varNest2 = 2;
// this is not ok
final Field f2 = Nest2.class.getDeclaredField("varNest2");
f2.setInt(nest2, 2);
}
}
public static class Nest2 {
private int varNest2;
}
public static void main(String[] args) throws Exception {
new Nest1().f();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment