DoubleToLongFunction是一个内置函数接口java.util.function函数Java8中引入的包。此函数接口接受双值参数并生成长值结果。DoubleToLongFunction接口可用作lambda表达式或方法引用的赋值目标。它只包含一个抽象方法:applyAsLong()。
@FunctionalInterface public interface DoubleToLongFunction { long applyAsLong(double value) }
import java.util.function.DoubleToLongFunction; public class DoubleToLongFunctionTest { public static void main(String args[]) { double dbl = 30.1212; DoubleToLongFunction castToLong = (dblValue) -> (long) dblValue; //lambda表达式 System.out.println(castToLong.applyAsLong(dbl)); dbl = 77.9212; DoubleToLongFunction roundToLong = Math::round; System.out.println(roundToLong.applyAsLong(dbl)); } }
输出结果
30 78