JDK 8の新特性--常用関数インターフェース--Lambanを使ってログを最適化した事例

1323 ワード

package comp.itheime.demo 02.Lambada;
@Funtional Interfacepublic interface Message Buider{
//             ,        
public abstract String builderMessage();
)package comp.itheim.demo 02.Lambada;/*
  Lambda      
Lambda   :    
Lambda     ,         
*/public class Demo 02 Lambada{
//           ,             MessageBuilder  
public static void showLog(int level, MessageBuilder mb){
    //          ,   1 ,   MessageBuilder    builderMessage  
    if(level==1){
        System.out.println(mb.builderMessage());
    }
}

public static void main(String[] args) {
    //        
    String msg1 = "Hello";
    String msg2 = "World";
    String msg3 = "Java";

    //  showLog  ,  MessageBuilder        ,      Lambda   
    /*showLog(2,()->{
        //           
        return  msg1+msg2+msg3;
    });*/

    /*
          Lambda         ,         showLog   
              ,      1 
                  MessageBuilder    builderMessage
                      
               ,       1 
              MessageBuilder      builderMessage     
                           
                   
     */
    showLog(1,()->{
        System.out.println("        ");
        //           
        return  msg1+msg2+msg3;
    });
}
)