//無輸入參數,返回T類型的一個結果。 new Supplier<String>() { @Override public String get() { return null; } }; Supplier<String> supplier = () -> "Test supplier"; supplier.get(); //return String | Test supplier //接受一個T類型的參數,無返回。 new Consumer<String>() { @Override public void accept(String s) { } }; Consumer<String> consumer = (x) -> { System.out.println(x); }; //Consumer<String> consumer = System.out::println; consumer.accept("Test consumer"); //void | 控制台打印 "Test consumer" //接受一個T類型的參數,返回布爾值。 new Predicate<String>() { @Override public boolean test(String s) { return false; } }; Predicate<String> predicate = x -> s.contains("predicate"); predicate.test("Test predicate"); //return boolean | true //接受一個T類型的參數,返回R類型結果。 new Function<String, Integer>() { @Override public Integer apply(String s) { return null; } }; Function<Integer,String> function = x -> "This is Integer:" + x; function.apply(100); //return String | "This is Integer:100"