Why is the @FunctionalInterface annotation added to the Comparator interface in Java 8?

I understand that a bunch of body methods have been added using the defaultJava 8 keyword . My question is, where is this annotation useful? I see that only one abstract method can be added with such annotation. But the comparator has two abstract methods:

  • int compare(T o1, T o2);
  • boolean equals(Object obj);

Also, please explain the use of this annotation? I see that this is a run-time annotation, so what uses it?

+4
source share
2 answers

From the documentationFunctionalInterface :

, java.lang.Object, , java.lang.Object .

equals java.lang.Object, . compare, FunctionInterface.

+6

, , . @FunctionalInterface , Java , , @FunctionalInterface. , .

+2

Source: https://habr.com/ru/post/1624681/


All Articles