I' m trying to understand @Functional interface from JDK and can't catch why did they create this annotation without a body?
I don't understand what is difference between using @FunctionalInterface in class description and not using? what does this annotation without params provide?
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface FunctionalInterface {}
If you add it, someone won't be able to add more methods without breaking your functional interface and will get a compile time error:
Invalid '@FunctionalInterface' annotation; MyInterface is not a functional interface
If a type is annotated with this annotation type, compilers are required to generate an error message unless:
- The type is an interface type and not an annotation type, enum, or class.
- The annotated type satisfies the requirements of a functional interface.