Hello,
The following Java code:
import java.util.Arrays;
import java.util.List;
class Main {
private String str = "";
void print(List<String> l) {
l.forEach(s -> str += s);
System.out.println(str);
}
}
works fine on my laptop with both of the following expressions
new Main().print(Arrays.asList("easy as", " 1", " 2", " 3")); new Main().print(List.of("easy as", " 1", " 2", " 3"))
Both output easy as 1 2 3
My compiler is javac 11.0.4 and the "java.class.version" property is 55.0.
On CodeRunner with Question type set to java_class, I submit the Main class code as an Answer and the expressions as Tests. The first expression yields the expected result. The second expression (using List.of) upsets the compiler which complains that
Syntax Error(s)
__tester__.java:21: error: cannot find symbol new Main().print(List.of("easy as", " 1", " 2", " 3")); ^ symbol: method of(String,String,String,String) location: interface List 1 errorIn CodeRunner, the "java.class.version" property is again 55.0.
Putting an expression with List.of into the Answer produces the same
unfriendly result. As does List<String>.of.
Any ideas of what's going wrong?