Ada yang mau bikin java berikutnya seperti ini (
http://www.javac.info)
static Pair<{ => int },{ => int }> joinedCounters(@Shared int initial) {
return Pair.<{ => int },{ => int }>of({ => initial++ }, { => initial++ });
}
static class Pair<T,U> {
static <T,U> Pair<T,U> of(T first, U second) { return new Pair<T,U>(first, second); }
Pair(T first, U second) {
this.first = first;
this.second = second;
}
final T first;
final U second;
}
public static void main(String[] args) {
Pair<{ => int }, { => int }> p = joinedCounters(10);
{ => int } c1 = p.first;
{ => int } c2 = p.second;
for (int i = 10; i<20; i++) {
int j = c1.invoke();
if (j != i) throw new AssertionError(i + " " + j);
}
for (int i = 20; i<30; i++) {
int j = c2.invoke();
if (j != i) throw new AssertionError(i + " " + j);
}
System.out.println("done");
}
Pusing ah liatnya. Semoga ga disetujui.