I wanted to learn the differences between Java 8 and Java 7. At the moment I am looking into the Java 8 forEach loop.
public class Main {
public static void main(String[] args){
List<String> strings = Arrays.asList("hello","my","name","is","test");
strings.stream().forEach(s -> System.out.println(s));
}
}
This code is generating the following error for me:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
s cannot be resolved to a variable
Syntax error on token "-", -- expected
s cannot be resolved to a variable
at Main.main(Main.java:7)
I am sure that the JDK aswell as the JRE are Java 8, since the compuler can recognize the forEach method from the List but not the -> parameter.
System.out.println(System.getProperty("java.version"));?1.8.0_25as output bySystem.getProperty(). However, the JDK is 1.7. God knows where Eclipse has that setting from though.