Lambda expressions are allowed only at source level 1.8 or above

The “source compatibility” part of the Java Compiler dialog has to be 1.8. Otherwise even though you’re allowed to use the library features of Java 1.8, you won’t be able to use the language features. It’s not just lambdas – there’s method references, static methods in interfaces, and default methods for example.

If source compatibility is lower versions of Java 1.8, you will face the following issue. This issue thrown compiling Java 8 source code in non Java 1.8 version.

Exception in thread “main” java.lang.Error: Unresolved compilation problems:

The method forEach(BiConsumer<? super String,? super Integer>) in the type Map<String,Integer> is not applicable for the arguments ((<no type> k, <no type> v) -> System.out.println((((“Item : ” + k) + ” Count : “) + v)))

Lambda expressions are allowed only at source level 1.8 or above

The method forEach(BiConsumer<? super String,? super Integer>) in the type Map<String,Integer> is not applicable for the arguments ((<no type> k, <no type> v) -> {

System.out.println((((“Item : ” + k) + ” Count : “) + v));

if (“E”.equals(k))

{

System.out.println(“Hello E”);

}

})

Lambda expressions are allowed only at source level 1.8 or above

at com.ehowtonow.java8.ForEachMap.main(ForEachMap.java:28)

How to enable source compatibility to Java 1.8 in Eclipse :

Refer the screenshot

In Eclipse goto Windows -> Preference

Apply the following settings to enable Java 8 “source compatibility”

java1.8 source


Ask your questions in eHowToNow Forum

Post your technical, non-technical doubts, questions in our site. Get answer as soon as possible, meanwhile you can help others by answering, unanswered questions.
To Ask new Question : Ask Question
Check our existing discussions : Questions & Answers

  1. Java 8 Stream Collectors groupingBy with sort Example
  2. Java – ToIntBiFunction Interface
  3. Java 8 Stream Filter with findAny orElse Example
  4. Java – BooleanSupplier Interface
  5. Java – DoubleSupplier Interface
  6. Java – DoubleConsumer Interface
  7. Java – Predicate Interface
  8. java.util.function Package
  9. Java – ToLongBiFunction Interface
  10. Java – Stream.Builder Interface
  11. Java 8 – filter the null values from Stream Example
  12. Java – IntToDoubleFunction Interface
  13. Java – DoubleStream Interface
  14. Lambda expressions are allowed only at source level 1.8 or above
  15. Java – BiFunction Interface

Be the first to comment

Leave a Reply