Why is it not possible to extend annotations in Java?

About the reason why it wasn’t designed that way you can find the answer in the JSR 175 Design FAQ, where it says:

Why don’t you support annotation subtyping (where one annotation type extends another)?

It complicates the annotation type
system, and makes it much more
difficult to write “Specific Tools”.

“Specific Tools” — Programs that query
known annotation types of arbitrary
external programs. Stub generators,
for example, fall into this category.
These programs will read annotated
classes without loading them into the
virtual machine, but will load
annotation interfaces.

So, yes I guess, the reason is it just KISS. Anyway, it seems this issue (along with many others) are being looked into as part of JSR 308, and you can even find an alternative compiler with this functionality already developed by Mathias Ricken.

Leave a Comment