Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

annotation represent another annotation

Is it possible to have an custom annotation that do the same work as another annotation ?

For example if I write @MyCustomAnnotation like I have write @override !

like image 346
M'hamed Avatar asked Jul 26 '12 23:07

M'hamed


People also ask

Can we apply two annotations together?

It is also possible to use multiple annotations on the same declaration: @Author(name = "Jane Doe") @EBook class MyClass { ... } If the annotations have the same type, then this is called a repeating annotation: @Author(name = "Jane Doe") @Author(name = "John Smith") class MyClass { ... }

Can you apply more than 1 annotation in a target?

You can repeat an annotation anywhere that you would use a standard annotation.

What is @target annotation in Java?

If an @Target meta-annotation is present, the compiler will enforce the usage restrictions indicated by ElementType enum constants, in line with JLS 9.7. 4. For example, this @Target meta-annotation indicates that the declared type is itself a meta-annotation type.

What is the use of @interface annotation?

The @interface element is used to declare an annotation. For example: @interface MyAnnotation{}


1 Answers

There's definitely no support for inheritance with Annotations. See: Is there something like Annotation Inheritance in java?

So without that, unless some framework chose to provide extensibility around its annotation processing, you would have a lot of trouble achieving such an effect.

like image 186
Jason Dunkelberger Avatar answered Oct 25 '22 10:10

Jason Dunkelberger