如何实现 ToIntBiFunction使用 Java 中的 lambda 表达式?
ToIntBiFunction<T, U> 是 java.util.function 包中的内置函数接口。该接口接受 两个参数作为输入并生成 整型值结果。ToIntBiFunction<T, U> 接口可用作 lambda 表达式或 方法引用的赋值目标。它只包含一个抽象方法:applyAsInt(),不包含任何 default 或 static 方法。
语法
@FunctionalInterface
interface ToIntBiFunction<T, U> {
int applyAsInt(T t, U u);
}示例
import java.util.function.ToIntBiFunction;
public class ToIntBiFunctionTest {
public static void main(String args[]) {
ToIntBiFunction<Integer, Integer> test = (t, u) -> t * u;
System.out.println("The multiplication of t and u is: " + test.applyAsInt(10, 7));
System.out.println("The multiplication of t and u is: " + test.applyAsInt(8, 15));
}
}输出
The multiplication of t and u is: 70 The multiplication of t and u is: 120
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP