We are moved to new domain
Click -> www.ehowtonow.com
Saturday, 17 June 2017

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.javatutorialcorner.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"








Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: Lambda expressions are allowed only at source level 1.8 or above Rating: 5 Reviewed By: eHowToNow