Skip to content

Instantly share code, notes, and snippets.

@chimerast
Created April 17, 2012 01:18
Show Gist options
  • Save chimerast/2402738 to your computer and use it in GitHub Desktop.
Save chimerast/2402738 to your computer and use it in GitHub Desktop.
初期化ブロックと継承の挙動の調査
public class Derived extends Base {
public String a = "initial";
public String b;
public static void main(String[] args) {
System.out.println("a: " + new Derived().a);
System.out.println("b: " + new Derived().b);
}
}
class Base {
public Base() {
try {
getClass().getField("a").set(this, "updated");
getClass().getField("b").set(this, "updated");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment