Therefore I have a question. Why do we even allow users to subclass
Annotation directly, if such subclasses aren't going to make much
sense anyways?
Is there any reason why TypeConstraint needs to extend Annotation and not StaticAnnotation?
If there are reasons for not inheriting from StaticAnnotation, we could at least put a @deprecatedInheritance annotation on Annotation itself.
This is all reasonable.
So what's basically missing is some kind of RuntimeAnnotation extending ClassfileAnnotation, which writes to the attribute section as a RuntimeVisibleAnnotation.
Btw, is there a reason why the proper flags are not set for annotations? For instance ...Btw, can we get rid of this “Implementation restriction: subclassing Classfile does not make your annotation visible at runtime.” non-sense?
A) The class is called ClassfileAnnotation and not Classfile.
B) Of course it doesn't make the annotation visible at runtime, that's the whole point of a ClassfileAnnotation. If we had a non-functional RuntimeAnnotation, then I'd understand an error message like that, but we don't.
Btw, is there a reason why the proper flags are not set for annotations? For instance ...
class FooAnnotation extends annotation.ClassfileAnnotation
val fa = classOf[FooAnnotation]
println(fa.isAnnotation)
... prints false!
As far as I see, currently none of them are set. (Only 0x1, but I guess that's something like ACC_PUBLIC).
Is there any reason, or is this just not implemented yet?
Doing it might be misleading because they are not really annotations in the java sense. ClassfileAnnotations would be if the scala compiler would support writing them.
Doing it might be misleading because they are not really annotations in the java sense. ClassfileAnnotations would be if the scala compiler would support writing them.
Btw, having looked at the spec, it would be a bit more work than for enums (where it is really only ACC_ENUM + extends Enum), but setting the right flags would probably be a huge step forward.
Did my email get lost somewhere? You can't set ACC_ANNOTATION without setting ACC_INTERFACE. You can't set ACC_INTERFACE without setting ACC_ABSTRACT. If you are ACC_ABSTRACT you cannot be instantiated. What are the right flags?
Sorry, maybe I didn't communicate properly. I meant to say that the amount of work left, once the right flags are set, is a bit higher for annotations than for enums.
I'm still trying to elicit your statement as to what are the "right flags" for annotations.