java_ Functional Programming

Create a function interface:

1  // defines a function interface 
2  @FunctionalInterface
 . 3  public  interface BlogTest {
 . 4      / * 
. 5      Functional Interface:
 6          concept: one and only one method of abstract interfaces
 7                interface comprises any other method (default, static, private )
 8          format:
 . 9              interface Interface name {
 10              public abstract method return type name (optional parameter information);
 11              other non-abstract methods content
 12              } 
 13          annotations: @FunctionalInterface a function of detecting whether the interface is interface
 14       * / 
15      
16     public  void Show ();
 . 17 }

 

Interface using the function:

1  // use the function interface 
2  class Test02 {
 . 3      // parameter is a function of process interface 
. 4      public  static  void show1 (BlogTest blogTest) {
 . 5          System.out.println ( "I is a function of interface" );
 6      }
 . 7  
. 8      public  static  void main (String [] args) {
 . 9          // call the function interface
 10          // method parameter is a function interface, can be transferred Show Lambda expressions ((arguments) 
. 11          show1 (() -> {});
 12      }
 13 }

 

Guess you like

Origin www.cnblogs.com/aikang525/p/11402766.html