Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Java in General and the fly likes @interface inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "@interface inheritance" Watch "@interface inheritance" New topic

@interface inheritance

Philip Pomario
Ranch Hand

Joined: Oct 03, 2003
Posts: 113
Why isn't it possible to extend custom annotations... ?

the following example does not compile:
@interface Base {}
@interface Derived extends Base {}
Jelle Klap

Joined: Mar 10, 2008
Posts: 1932

The specification doesn't allow it.
JLS3 wrote:
No extends clause is permitted. (Annotation types implicitly extend annotation.Annotation.)

Maybe the rationale behind this can be found somewhere in the discussions leading up to the specification in JSR175.

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
I agree. Here's the link:
subject: @interface inheritance
It's not a secret anymore!