(List<String> list) -> list.isEmpty() // 布尔类型表达式
() -> new Apple(10) // 创建一个新对象
(Apple a) -> { System.out.println(a.getWeight()); } // 使用一个对象的属性
(String s) -> s.length() // 选择或提取一个对象的属性
(int a, int b) -> a * b // 组合两个参数
(Apple a1, Apple a2) -> a1.getWeight().compareTo(a2.getWeight()) // 比较两个对象
// java.util.Comparator
public interface Comparator<T> {
public int compare(T o1, T o2);
}
inventory.sort(new Comparator<Apple>() {
public int compare(Apple a1, Apple a2){
return a1.getWeight().compareTo(a2.getWeight());
}
});
inventory.sort((Apple a1, Apple a2) -> a1.getWeight().compareTo(a2.getWeight() ) );
Thread t = new Thread(new Runnable() {
public void run(){
System.out.println("Hello world");
}
});
Thread t = new Thread(() -> System.out.println("Hello world"));
Button button = new Button("Send");
button.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
label.setText("Sent!!");
}
});
Button button = new Button("Send");
button.setOnAction((ActionEvent event) -> label.setText("Sent!!"));
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有