java8 --- (Function, Predicate, Consumer) common interface function

 

 

//    public static void main(String[] args) throws InterruptedException {  // https://blog.csdn.net/u011848397/article/details/89074794

//        String name = "";
//        String name1 = "12345";
//
//        //3.Predicate<T>
//        String name2 = "12";
//        System.out.println(validInput(name, inputStr ->  !inputStr.isEmpty() &&  inputStr.length() <= 3 ));
//        System.out.println(validInput(name2,inputStr ->  !inputStr.isEmpty() &&  inputStr.length() <= 3 ));
//        System.out.println(validInput(name1,inputStr ->  !inputStr.isEmpty() &&  inputStr.length() <= 3 ));

//        //2.Predicate <T>
 //         the ValidInput (? Name, (Consumer <String>) inputstr -> System.out.println (inputStr.isEmpty () "name can not be empty": "normal name"));
 //         the ValidInput (? name1, (Consumer <String >) inputStr -> System.out.println (inputStr.isEmpty () " name can not be empty": "normal name")); 

//         // 1.Function <T, R>
 //         System.out.println (? the ValidInput (name, i -> i.isEmpty () "name can not be empty": i));
 //         System.out.println (the ValidInput (NAME1, i -> i.length ()> 3 "long names": I));?
 //     } 

//     // 3.Predicate <T>: the T as input and returns as output a Boolean value, which comprises a plurality of interfaces to the default method Predicate combined into other complex logic (aND, oR, NOT).
//    static Boolean the ValidInput public (String name, the Predicate <String> function) {
 //         return function.test (name);
 //     } 

//     // 2.Consumer <T>: T as the input, does not return any content, expressed operate on a single parameter.
//     public static void the ValidInput (String name, Consumer <String> function) {
 //         function.accept (name);
 //     }
 // 
//     // 1.Function <T, R & lt>: the T as input and returns R as an output, the method further comprising default functions and other combinations.
//     public static String the ValidInput (String name, Function <String, String> function) {
 //         return Function.apply (name);
 //     }

Guess you like

Origin www.cnblogs.com/hahajava/p/12074760.html