Java . util . function . longbinaryooperator 接口示例
原文:https://www . geesforgeks . org/Java-util-function-longbinaryooperator-interface-with-examples/
在 Java 8 中引入了longbinaryooperator接口。它表示对两个长值的操作,并将结果作为长值返回。这是一个功能接口,因此可以用作 lambda 表达式或方法引用。它主要用于需要从用户封装操作的时候。
方法:
-
【applyAsLong()】 : This function takes two long values, performs the required operation, and returns the long value.
```java public long applyAsLong(long val1, long val2)
```
将 LongBinaryOperator 界面演示为λ表达式的示例。
// Java program to demonstrate LongBinaryOperator
import java.util.function.LongBinaryOperator;
public class LongBinaryOperatorDemo {
public static void main(String[] args)
{
LongBinaryOperator longBinaryOperator = (x, y) ->
{
return x + y;
};
System.out.print("343666 + 547477 = ");
System.out.println(longBinaryOperator
.applyAsLong(343666, 547477));
LongBinaryOperator longBinaryOperator1 = (x, y) ->
{
return x * y;
};
System.out.print("343666 * 547477 = ");
System.out.println(longBinaryOperator1
.applyAsLong(343666, 547477));
}
}
输出:
343666 + 547477 = 891143
343666 * 547477 = 188149230682
参考:https://docs . Oracle . com/javase/8/docs/API/Java/util/function/longbinaryooperator . html
版权属于:月萌API www.moonapi.com,转载请注明出处