Are compiled Java 8 lambda expressions backwards compatible with earlier versions of the Java runtime?

你说的曾经没有我的故事 提交于 2019-11-29 03:44:06

In general it is not possible to have Javac compiler use a source level that is higher than the target JVM level. Thus the answer is NO.

Officially no, but for an unofficial solution you should look at the Retrolambda project. It doesn't backport the Collection API changes, but it can handle lambda expressions (and method references) for you.

I dont believe so - the bytecode version is different (52 i think) and lambda uses invokedynamic and not get translated into anonymous classes..

Java 8 introduces a new concept of default method implementation in interfaces. This capability is added for backward compatibility so that old interfaces can be used to leverage the lambda expression capability of Java 8. For example, ‘List’ or ‘Collection’ interfaces do not have ‘forEach’ method declaration. Thus, adding such method will simply break the collection framework implementations. Java 8 introduces default method so that List/Collection interface can have a default implementation of forEach method, and the class implementing these interfaces need not implement the same.

public interface vehicle {
  default void print(){
      System.out.println("I am a vehicle!");
                       }
                          }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!