I was reading about java annotation and a new doubt appears.
In the documentation explain the FunctionalInterface Annotation Type:
An interface with one abstract method declaration is known as a functional interface.The compiler verifies all interfaces annotated with a @FunctionalInterface that the interfaces really contain one and only one abstract method. A compile-time error is generated if the interfaces annotated with this annotation are not functional interfaces. It is also a compile-time error to use this annotation on classes, annotation types, and enums. The FunctionalInterface annotation type is a marker interface.
I did some test and I did not need to mark my interface with this annotation type. Then, my question is: Why do I need this annotation if every interface with one method is always a functional interface?
Exampe Code
// @FunctionalInterface
interface Wizard {
int spell(String power);
}
class TestLambda {
public static void main(String[] args) {
Wizard gandalf = str -> str.length();
int power = gandalf.spell(args[0]);
System.out.println("The spell length is: " + power+ " points");
}
}