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?
ROMANIA_engineer
57.1k30 gold badges211 silver badges207 bronze badges
asked Sep 2, 2015 at 6:33
codegasmer
1,4781 gold badge18 silver badges47 bronze badges
1 Answer 1
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.
Sotirios Delimanolis
281k62 gold badges718 silver badges744 bronze badges
answered Sep 2, 2015 at 7:10
codegasmer
1,4781 gold badge18 silver badges47 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
buherator
I suppose you're referring to the JAVA_HOME environment variable
Explore related questions
See similar questions with these tags.
lang-java
javac -versionjavac -version.