1.编写函数式接口
@FunctionalInterface
private interface Test2<T>{
public T getResult(int a,int b);
}
2编写测试类
@Test
public void addTest(){
Test2<Integer> test2 = (a,b)->{
int result = 0;
result = a+b;
return result;
};
System.out.println(test2.getResult(3,4));
}
3.运行
Connected to the target VM, address: '127.0.0.1:54373', transport: 'socket'
OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
The result is:7
Disconnected from the target VM, address: '127.0.0.1:54373', transport: 'socket'
Process finished with exit code 0