7

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 !

Pritam
  • 339
  • 3
  • 23
M'hamed
  • 2,508
  • 3
  • 24
  • 41
  • 1
    is there any reason you would want to? The annotations give a good indication to other developers as to what you are doing, if you change them for your own words they will mean nothing to other developer anymore. – Jon Taylor Jul 26 '12 at 23:18
  • exactly ... if the annotation name change you have to change all occurrence of that annotation in your code but if I was able to have it override I will only changed one time ! – M'hamed Jul 26 '12 at 23:40
  • There are many use cases, like to make all `@Api` methods also `@SuppressWarning("unused")` (or to force them @NotNull), to make `@OldApi` also `@Deprecated`... – tango24 Nov 09 '20 at 11:12

1 Answers1

1

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.

Community
  • 1
  • 1
Jason Dunkelberger
  • 1,207
  • 14
  • 18