|
|
|
int i; new (i) { public int getI() { return i; } } new (membername: 42) { public int getI() { return membername; } |
|
interface IntAdder { public int operator+(int j); } int i = 42; IntAdder adder = new (i) implements IntAdder { public int operator+(int j) { return i + j; } }; int j = adder + 4; // j == 46 // This Code will internally tranformed to: class Closure1 extends IntAdder { public Closure1(int i_) : i(i_) {} public int operator+(int j) { return i + j; } } IntAdder adder = new Closure1(i); |
|
interface Dumper { public void operator()(String s); } Dumper dumper = new () implements Dumper { public void operator()(String s) { System.out.println(s); } }; dumper("asdf"); |