所谓函数时接口,就是只定义了单一抽象方法的接口,如下:
@FunctionalInterface
public interface ITest {
Integer square(int val);
}
然后在使用时就可以通过lambda表达式对该方法进行实现,代码如下:
public class Main {
public static void main(String[] args) throws IOException {
ITest iTest = val -> val * val;
System.out.println(iTest.square( 100 ));
}
}