几种函数接口
package org.java8.lambda;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Supplier;
import lombok.extern.slf4j.Slf4j;
/*Predicate<T> T boolean 这张唱片已经发行了吗
Consumer<T> T void 输出一个值
Function<T,R> T R 获得Artist对象的名字
Supplier<T> None T 工厂方法
UnaryOperator<T> T T 逻辑非 (!)
BinaryOperator<T> (T, T) T 求两个数的乘积 (*)*/
@Slf4j
public class FunctionInterface {
public static void main(String[] args) {
log.info("Predicate boolean : {}", getPredicate().test(1>2));
consumer().accept("haha");
log.info("supplier: {}",supplier().get());
}
private static Consumer<String> consumer() {
return new Consumer<String>() {
@Override
public void accept(String t) {
log.info("accept value: {}", t);
}
};
}
public static Supplier<String> supplier() {
return new Supplier<String>() {
@Override
public String get() {
return UUID.randomUUID().toString();
}
};
}
public static Predicate<Boolean> getPredicate() {
return new Predicate<Boolean>() {
@Override
public boolean test(Boolean t) {
return t;
}
};
}
}