Skip to content

Instantly share code, notes, and snippets.

@kurogelee
Created April 25, 2014 10:46
Show Gist options
  • Save kurogelee/11285273 to your computer and use it in GitHub Desktop.
Save kurogelee/11285273 to your computer and use it in GitHub Desktop.
インスタンスイニシャライザ実行とフィールド初期化はどっちが先に? ref: http://qiita.com/kurogelee/items/09e5270385d14148f5e8
field1
initializer1
field2
initializer2
constructor
package basic;
import java.util.function.*;
public class Init {
Init(){
p("constructor");
}
int i = ((IntSupplier)(() -> { p("field1"); return 0; })).getAsInt();
{
p("initializer1");
}
int j = ((IntSupplier)(() -> { p("field2"); return 0; })).getAsInt();
{
p("initializer2");
}
static void p(String s){
System.out.println(s);
}
public static void main(String... args){
new Init();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment