Java 8 for OSX but not lamba
Henri Gomez
henri.gomez at gmail.com
Wed Mar 14 13:04:27 PDT 2012
Hi to all,
I guess JDK 8 and Lambda gurus are around (ie: Remy).
I build JDK8 for OSX and package it in openjdk-osx-build project :
http://openjdk-osx-build.googlecode.com/files/OpenJDK-OSX-8-x64-jdk-b29-20120314.dmg
I tried a sample code from
http://aruld.info/lambda-expressions-in-java-8-adopts-c-style-syntax/
:
public class Sample4 {
enum Decision {
APPROVE, DECLINE, APPROVE_REFER
}
interface DecisionService {
Decision getRiskDecision(Applicant applicant);
}
class Applicant {
private int score;
public Applicant(int score) {
this.score = score;
}
public int getScore() {
return score;
}
}
public void test() {
DecisionService cs = (a) -> {
if (a.getScore() > 700) {
return Decision.APPROVE;
} else if (a.getScore() > 600 && a.getScore() < 650) {
return Decision.APPROVE_REFER;
} else {
return Decision.DECLINE;
}};
Decision decision = cs.getRiskDecision(new Applicant(800));
System.out.println(decision.toString());
}
public static void main(String... args) {
new Sample4().test();
}
}
Bur javac failed to compile it :
Sample4.java:24: error: lambda expressions are not supported in -source 1.8
DecisionService cs = (a) -> {
^
(use -source 8 or higher to enable lambda expressions)
1 error
* Did Lambda support is not yet in jdk8/jdk8 branch ?
* Why did javac complain about source 1.8 and ask for -source 8 (tried
to force it but same error)
Cheers
More information about the mlvm-dev
mailing list