Lambdas Flashcards

1
Q

What is the method signature of Predicate

A

public boolean test(T t)

It only has one abstract method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Can a functional interface have other default or static methods?

A

Yes, but it must also have exactly one abstract method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Is the following a valid lambda expression?

foo(newArrayList( ), ArrayList a1 -> a1.isEmpty ( ) );

A

No.

The parameter list should be in parenthesis:

foo(newArrayList( ), (List a1) -> a1.isEmpty( ) );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What syntax is needed to use the return keyword in a lambda expression?

A

Curly braces.

ex.: foo(new ArrayList( ), al -> { return al.size( ) == 0; } );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Does a lambda expression create a new scope for variables?

A

No.

You may not reuse variable names already defined as new variables in a lambda expression argument list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

When can you omit curly braces in a lambda expression?

A

When all the method does is return the value of an expression.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the only method of the java.util.function.Predicate interface?

A

test ( )

It returns a boolean.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly