Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Annotation implement interfaces?

Tags:

Is there any possibility implement interface in annotation? Something like:

public @interface NotNull implements LevelInterface  {     ValidationLevel level(); }; 
like image 567
Kucera.Jan.CZ Avatar asked Jan 18 '11 09:01

Kucera.Jan.CZ


People also ask

Are annotations interfaces?

Annotation types are a form of interface, which will be covered in a later lesson. For the moment, you do not need to understand interfaces. The body of the previous annotation definition contains annotation type element declarations, which look a lot like methods. Note that they can define optional default values.

Which annotation can be used to ensure that an interface?

@FunctionalInterface annotation is used to ensure that the functional interface can't have more than one abstract method.

What is the purpose of annotation in Java?

Java annotations are metadata (data about data) for our program source code. They provide additional information about the program to the compiler but are not part of the program itself. These annotations do not affect the execution of the compiled program.

How do you calculate implementation annotation?

The only way to look for ALL implementations which hold the specific interface is to call on Person i.e. Person. class. getAnnotations() . This unfortunately only yields the annotations which are declared on the Person interface.


1 Answers

No, the compiler says:

Annotation type declaration cannot have explicit superinterfaces

You cannot extend either:

Annotation type declaration cannot have an explicit superclass

like image 65
Thilo Avatar answered Nov 04 '22 07:11

Thilo