[JSR308] Custom annotations?

Michael Ernst mernst at csail.mit.edu
Tue Feb 12 16:15:44 EST 2008


I think our messages regarding implementation strategy may have crossed.
(Sorry for my slow responses to your messages; I am suffering from poor
Internet connectivity at the moment.)

> The basic idea is:
> I have one annotation which tells other annotations are 'much like a 
> typecast' , as we have in C++. Recapping from  previous thread:

I don't think that you need to add a Typecast annotation or to tie the Rate
and Volatility annotations together.  The two can be checked independently.
In particular, this:

        double rate = 1.0;
        @Volatility double vol = rate;

is as much an error as this:

        @Rate double rate = 1.0;
        @Volatility double vol = rate;

In either case the problem is that the vol variable is being assigned from
a value whose type lacks the @Volatility annotation (regardless of what
annotation, if any, its type has).

> 2. Is it correct to say that's enough to have RetentionPolicy=SOURCE for
> @Rate and @Volatility annotations? My aim is to avoid any performence
> penalty as possible at runtime due to performance concerns.

That's should work fine if you always compile your entire codebase from
.java files, without ever reading pre-compiled .class files.  If you want
to do the latter, then you'll probably want to retain the annotation at
least into the class files, so that the compiler can read the annotations
on signatures and verify the correctness of method calls into libraries.
You also might want to experiment to see whether a different
RetentionPolicy has a significant impact in your domain.


More information about the JSR308 mailing list