Lambdas Flashcards
What is the method signature of Predicate
public boolean test(T t)
It only has one abstract method.
Can a functional interface have other default or static methods?
Yes, but it must also have exactly one abstract method.
Is the following a valid lambda expression?
foo(newArrayList( ), ArrayList a1 -> a1.isEmpty ( ) );
No.
The parameter list should be in parenthesis:
foo(newArrayList( ), (List a1) -> a1.isEmpty( ) );
What syntax is needed to use the return
keyword in a lambda expression?
Curly braces.
ex.: foo(new ArrayList( ), al -> { return al.size( ) == 0; } );
Does a lambda expression create a new scope for variables?
No.
You may not reuse variable names already defined as new variables in a lambda expression argument list.
When can you omit curly braces in a lambda expression?
When all the method does is return the value of an expression.
What is the only method of the java.util.function.Predicate interface?
test ( )
It returns a boolean.