@FunctionalInterface
public interface Function<T, R> {
R apply(T t);
}
public static void main(String[] args) {
// 这里用到了Java8的 方法引用,功能型函数式接口!
Function<String,Boolean> function = "Hello Java" :: endsWith;
System.out.println(function.apply("Java"));
}
@FunctionalInterface
public interface Consumer<T> {
void accept(T t);
}
class TestDemo{
//此方法没有返回值,但是有输入参数
public void fun(String str){
System.out.println(str);
}
}
public class TestFunctional {
public static void main(String[] args) {
TestDemo demo = new TestDemo();
//消费型接口,只有输入参数,没有输出参数
Consumer<String> consumer = demo :: fun;
consumer.accept("");
}
}
@FunctionalInterface
public interface Supplier<T> {
T get();
}
public class TestFunctional {
public static void main(String[] args) {
//供应商类型接口,只有输出参数,没有输入参数!
Supplier<String> supplier = "java 8" :: toUpperCase;
System.out.println(supplier.get());
}
}
@FunctionalInterface
public interface Predicate<T> {
boolean test(T t);
}
public class TestFunctional {
public static void main(String[] args) {
//断言类型接口。有输入参数,输出参数为布尔值
Predicate<String> predicate = "Android" :: equalsIgnoreCase;
System.out.println(predicate.test("android"));
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有