Reputation: 1468
I have recently updated my java to the 8th version and trying some Lambdas but it's giving error.
My Code
String[] st = {"ak","ss","dd"};
Arrays.asList(st).forEach(data -> System.out.println(data));
The output of the console is
PS E:\> javac .\Lambdas.java
.\Lambdas.java:11: error: illegal start of expression
Arrays.asList(st).forEach(data -> System.out.println(data));
^
1 error
PS E:\> java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
This is strange because I have java 8 as seen above but my code in not compiling.
Is there anything I am doing wrong?
Upvotes: 5
Views: 5078
Reputation: 1468
It's the compiler issue. In my environment variable I was pointing towards the old java 7 version. After changing it to 8 the code compiled.
Upvotes: 3