Generic lambdas
Miles Sabin
miles at milessabin.com
Wed Nov 16 09:59:10 PST 2011
I've just been attempting to play with generic lambdas using the
binary JDK 8 snapshot posted a few days ago,
miles at lewis:lambda$ /usr/java/lambda-jdk/bin/java -version
openjdk version "1.8.0-ea"
OpenJDK Runtime Environment (build 1.8.0-ea-b1314)
OpenJDK 64-Bit Server VM (build 23.0-b04, mixed mode)
I took this example from the EDR,
public class Lambda {
public static interface Picker {
<T> T pick(T first, T second);
}
public static void main(String[] args) {
Picker rand = <T> (T first, T second) -> new
Random().nextBoolean() ? first : second ;
int i = rand.pick(1, 2);
String s = rand.pick("a", "b");
}
}
But this fails compilation as follows,
miles at lewis:lambda$ /usr/java/lambda-jdk/bin/javac Lambda.java
Lambda.java:7: error: illegal start of expression
Picker rand = <T> (T first, T second) -> new
Random().nextBoolean() ? first : second ;
^
1 error
Is this expected at present?
Cheers,
Miles
--
Miles Sabin
tel: +44 7813 944 528
gtalk: miles at milessabin.com
skype: milessabin
g+: http://www.milessabin.com
http://twitter.com/milessabin
http://www.chuusai.com/
More information about the lambda-dev
mailing list