determine the behavior of this program:.
public class Main { @FunctionalInterface/*from w w w. ja v a 2 s. c o m*/ interface LambdaFunction { int apply(int j); boolean equals(java.lang.Object arg0); } public static void main(String []args) { LambdaFunction lambdaFunction = i -> i * i; // #1 System.out.println(lambdaFunction.apply(10)); } }
lambdaFunction
that defines two abstract methodsD.
an interface can be defined inside a class.
the signature of the equals method matches that of the equal method in Object class; hence it is not counted as an abstract method in the functional interface.
it is acceptable to omit the parameter type when there is only one parameter and the parameter and return type are inferred from the lambdaFunction
abstract method declaration int apply(int j).
since the lambda function is passed with the value 10, the returned value is 10 * 10, and hence 100 is printed in console.