Q53: What are Lambda Expressions and Functional Interfaces in Java 8?
- Functional Interface: An interface containing exactly one abstract method (annotated with
@FunctionalInterface). Examples:Runnable,Callable,Comparator. - Lambda Expression: Concise anonymous method implementation ($(text{params}) to {text{body}}$). Invoked via bytecode instruction
invokedynamic.
Key Takeaways
- Functional Interfaces hold exactly one abstract method.
- Lambdas compile to
invokedynamiccall sites instead of anonymous class allocations.
Knowledge Check
Can an interface annotated with @FunctionalInterface contain default and static methods?