How do you assign a lambda to a variable in Java 8?

前端 未结 3 897
臣服心动
臣服心动 2020-12-14 13:52

Just playing with the new lambda and functional features in Java 8 and I\'m not sure how to do this.

For example the following is valid:

    Map<         


        
3条回答
  •  暖寄归人
    2020-12-14 14:51

    example of passing a lambda containing a method

    YourClass myObject = new YourClass();
    
    // first parameter, second parameter and return 
    BiFunction YourFunction; 
    
    YourFunction = (k, v) -> v == null ? "ERROR your class object is null" : defaultHandler("hello",myObject);
    
    public String defaultHandler(String message, YourClass Object)
    {
         //TODO ...
    
         return "";
    }
    

提交回复
热议问题