Created
April 17, 2012 01:18
-
-
Save chimerast/2402738 to your computer and use it in GitHub Desktop.
初期化ブロックと継承の挙動の調査
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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