💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
### JAVA8 方法引用 ![](https://img.kancloud.cn/51/e7/51e741e4811ee74c46c90bc99acfed6d_904x294.png) ``` // 方法一:传递代码 public class AppleComparator implements Comparator<Apple> { public int compare(Apple a1, Apple a2){ return a1.getWeight().compareTo(a2.getWeight()); } } inventory.sort(new AppleComparator()); // 方法二:实用匿名类 inventory.sort(new Comparator<Apple>() { public int compare(Apple a1, Apple a2){ return a1.getWeight().compareTo(a2.getWeight()); } }); // 方法三:实用lambda表达式 inventory.sort((Apple a1, Apple a2) -> a1.getWeight().compareTo(a2.getWeight()) ); inventory.sort((a1, a2) -> a1.getWeight().compareTo(a2.getWeight())); // 方法四:实用方法引用 inventory.sort(comparing(Apple::getWeight)); // java.util.Comparator.comparing ```