path | title |
---|---|
/learnings/java_lambdas |
Learnings: Java: Lambdas |
Useful interfaces:
-
Predicate p = (in) -> false
-
BinaryOperator p = (T one, T two) -> two (All must be of same type)
https://docs.oracle.com/javase/8/docs/api/java/util/function/package-summary.html
<<Java_Lambda_Outside_Variable_Restrictions>>
- Variables used in lambda must be final or effectively final - no reassigning values / no __block syntax
If you have some Java code like so
interface ThisCallable {
void doIt(int c);
}
class Example {
void higherOrderFunction(ThisCallable x) {
...
}
}
Since ThisCallable
is a Java Single Abstract Method Interface Java 8+ - will figure it out if you just pass a lambda (in either language)