@Test
public void test6() {
Consumer<String> consumer = x -> System.out.println(x);
consumer.accept("demo");
Consumer<String> consumer1 = System.out::println;
consumer.accept("demo1");
Supplier<People> peopleSupplier = People::new;
System.out.println(peopleSupplier.get());
Comparator<Integer> comparator = (x, y) -> Integer.compare(x, y);
System.out.println(comparator.compare(1, 2));
Comparator<Integer> comparator1 = Integer::compare;
System.out.println(comparator1.compare(2, 1));
Function<Double, Long> function = (x) -> Math.round(x);
System.out.println(function.apply(12.3));
Function<Double, Long> function1 = Math::round;
System.out.println(function1.apply(12.6));
Comparator<String> comparator2 = (x,y)-> x.compareTo(y);
System.out.println(comparator2.compare("a","b"));
Comparator<String> comparator3 = String::compareTo;
System.out.println(comparator3.compare("a", "a"));
People people1 = new People();
Function<People,String> function2 = people -> people.getName();
System.out.println(function2.apply(people1));
Function<People,String> function3 = People::getName;
System.out.println(function3.apply(people1));
}
}
class People {
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
String name;
@Override
public String toString() {
return "People{" +
"name='" + name + '\'' +
", sex='" + sex + '\'' +
", age=" + age +
'}';
}
public People() {
this.name = "name";
this.sex = "female";
this.age = 18;
}
String sex;
int age;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗