Advanced - Functional Interfaces, Lambdas, etc. Flashcards
1
Q
What are functional interfaces? List some that come with the JRE for Java 8
A
A functional interface is an interface that contains only one abstract method. They can have only one functionality to exhibit. From Java 8 onwards, lambda expressions can be used to represent the instance of a functional interface. A functional interface can have any number of default methods.
- Runnable
- ActionListener
- Comparable
- Comparator
2
Q
What are lambdas?
A
A lambda expression is a short block of code which takes in parameters and returns a value. Lambda expressions are similar to methods, but they do not need a name and they can be implemented right in the body of a method.