August 2018
Beginner
178 pages
4h 56m
English
Java has numerous functional interfaces that have only one method. They are called SAM types, which stands for Single Abstract Method. One example of that kind of interface is IntPredicate from the Java standard library:
@FunctionalInterfacepublic interface IntPredicate { /** * Evaluates this predicate on the given argument. * * @param value the input argument * @return {@code true} if the input argument matches the predicate, * otherwise {@code false} */ boolean test(int value);}
In the next example, we are trying to create this interface with a lambda, but the compiler will throw an error:
fun createPredicate(): IntPredicate { //compiler error return { n: Int -> n % 2 == 0 }}
Even though the function signature of the ...
Read now
Unlock full access