Java8的lambda表达式学习记录—java.util.function 四大内置函数式接口
一,Consumer : 消费型接口
@FunctionalInterface
public interface Consumer<T> {
/**
* Performs this operation on the given argument.
*
* @param t the input argument
*/
void accept(T t);
}
有参数,无返回值。
public void go1(double money, Consumer consumer){
consumer.accept(money);
}
//示例 :
@Test
public void test(){
go1(10000.00, (t) -> System.out.println("消费了10000.00元"));
}
二,Supplier : 供给型接口
@FunctionalInterface
public interface Supplier<T> {
/**
* Gets a result.
*
* @return a result
*/
T get()