代碼
提交代碼
import java.util.Comparator;
import java.util.function.Function;
public class MethodReferencesDemo3 {
public static void main(String[] args) {
// 使用 Lambda 表達(dá)式
Function<Double, Long> function1 = d -> Math.round(d);
Long apply1 = function1.apply(1.0);
System.out.println(apply1);
// 使用方法引用,類 :: 靜態(tài)方法( round() 為靜態(tài)方法)
Function<Double, Long> function2 = Math::round;
Long apply2 = function2.apply(2.0);
System.out.println(apply2);
}
}
運(yùn)行結(jié)果