如何實現 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