java8 common function interface Supplier, Consumer, Predicate, Function summary

        // no input parameters and returns a result of type T. 
        Supplier new new <String> () { 
            @Override 
            public GET String () { 
                return null; 
            } 
        }; 
        Supplier <String> Supplier = () -> "the Test Supplier"; 
        supplier.get (); // return String | the Test Supplier 

        // accepts a parameter of type T, no return. 
        Consumer new new <String> () { 
            @Override 
            public void Accept (String S) { 

            } 
        }; 
        Consumer <String> Consumer = (X) -> { 
            System.out.println (X); 
        };  
        // Consumer <String> consumer = System.out :: println;
        consumer.accept ( "the Test consumer "); // void | console Print"

        // accepts a parameter of type T, returns a Boolean value. 
        the Predicate new new <String> () { 
            @Override 
            public Boolean Test (String S) { 
                return to false; 
            } 
        }; 
        the Predicate <String> the predicateA = X -> s.contains ( "the predicateA"); 
        predicate.test ( "the predicateA the Test" ); // return Boolean | to true 

        // to accept a parameter of type T and returns the result R type. 
        Function new new <String, Integer> () { 
            @Override 
            public Apply Integer (String S) {  
                return null; 
            } 
        };
        Function <Integer, String> = function X -> "This IS Integer:" + X; 
        Function.apply (100); // return String | "This is Integer: 100 "

  

Guess you like

Origin www.cnblogs.com/sueyyyy/p/12095814.html