@Inherited for Invariant Annotations?

When I wrote the API code for xajavac, my Java compiler variant that allows subtyping for annotations, I discovered the @Inherited annotation for the first time. This annotation is used on another annotation and indicates that the other annotation should be inherited from superclasses to subclasses. Specifically, annotations with @Inherited also appear in the array of annotations returned by Class.getAnnotations() if they annotated any of the superclasses of the class in question; in contrast, the array returned by Class.getDeclaredAnnotations only returns the annotations that are actually annotation the class itself.

When I wrote the implementation of the invariant checker outlined in my Master’s thesis, I implemented and described an inheritance mechanism for these invariant annotations that didn’t rely on the @Inherited annotation. I introduced separates meta-annotation, @PredicateLink and @Combine, which I needed anyway and which also incorporated the meaning of @Inherited.

Now that I have discovered @Inherited, I’m wondering whether I could or even should use it. That would mean making non-inheritance the default behavior, and letting @Inherited imply the inheriting case. I don’t think that’s the behavior I want. A @NotInherited meta-annotation would be better.

Share

About Mathias

Software development engineer. Principal developer of DrJava. Recent Ph.D. graduate from the Department of Computer Science at Rice University.
This entry was posted in Concurrent Unit Testing, xajavac. Bookmark the permalink.

Leave a Reply