Illustrates jdk1.8 novel properties (1)

Illustrates jdk1.8 novel properties (1)

Functional Interface

To sum up the following points:

  • If the interface to become a function interface (function interface can be simplified manner directly lambda), there must be one and only one abstract method (default and non-static)

  • Notes can be @FunctionalInterfaceannotated by being given to prevent others from damage functional interfaces at compile time


Interface default and static methods

Summarized as follows:

  • After jdk1.8 interfaces default methods and static methods can be implemented, in fact, an interface as an abstract class
  • default non-static method must be invoked through the interface implementation class, interface class can be rewritten in this method. The static methods can be called directly via the interface.

Method references

Summarized as follows:

  • Reference method can only be used as a method of argument, it can not be used to create objects in the new
  • The method as cited parameters, parameter types must be a function of the original interface or otherwise be a lambda expression
  • Reference new objects out of a method which is substantially a lamba subclass functional interface does not work at this time polymorphism

Guess you like

Origin www.cnblogs.com/Kidezyq/p/11727708.html