annotations
Stuart McCulloch
mcculls at gmail.com
Fri Apr 17 22:07:24 EDT 2009
2009/4/18 Evan Cowden <evan38109 at gmail.com>
> > I guess your argument against annotations doesn't translate into support
> > for the 'requires' keyword in module-info.java, right? We need some way
> > for a Java compiler to read raw dependency data, and for
> > module-system-specific metadata to qualify that data. Hence my proposal:
> >
> > // Non-dependency, post-classloading annotations make sense up here
> > @Copyright("Alex")
> > module M @ 1.5 { // Or M : 1.5 as per Paul's comments
> >
> > requires FOO BAR QUUX N at 1.6;
> > // FOO BAR QUUX interpreted by a module system, to be identified
> > // an attribute in module-info.class.
> > }
> >
> > Alex
>
> Interesting idea. It's a move in the right direction, but I think
> you're still going to have the same problems.
>
> Let's flesh out that example:
>
> // You need to import the annotation classes
> import com.alex.Copyright;
> import com.sun.jigsaw.annotations.Jigsaw;
> import org.osgi.annotations.OSGi;
>
> // Non-dependency, post-classloading annotations make sense up here
> @Copyright("Alex")
> @Jigsaw("...")
> @OSGi("...")
> module M @ 1.5 { // Or M : 1.5 as per Paul's comments
>
> requires FOO BAR QUUX N at 1.6;
> // FOO BAR QUUX interpreted by a module system, to be identified
> // an attribute in module-info.class.
> }
>
> If the module-info.java works in the same was as package-info.java -
> at least in my understanding - then we'll wind up with a
> module-info.class. This is then read in by the module system through
> the classloading process. The classloader hits those import
> statements for the annotations and immediately replies, "huh?"
> (Forgive me if I'm mischaracterizing classloaders.) The class never
> gets successfully loaded and you still can't get your metadata.
>
you can load a class without having all the annotation classes available
on the classpath - however, annotations whose classes are missing will
then not be visible via reflection, etc.
for example:
a.java:
//==============================
import java.lang.annotation.*;
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface a {}
//==============================
main.java:
//==============================
import java.util.*;
@a
public class main {
public static void main(String[] args) {
System.out.println(Arrays.toString(main.class.getAnnotations()));
}
}
//==============================
$ javac a.java main.java
$ java main
[@a()]
$ rm a.class
$ java main
[]
IIRC this was one of the design goals behind annotations
Meanwhile, let's say that I'm trying to get my module to work in two
> module systems - for the purposes of this example, Jigsaw and OSGi.
> Whenever I load it into Jigsaw, I need to import the module with
> OSGi's annotations (which are hopefully set up to be read by Jigsaw),
> and visa versa. This isn't the end of the world, but with multiple
> module systems and user extensions for each, it's not hard to start
> imagining some real nightmare scenarios.
>
> - Evan Cowden
>
--
Cheers, Stuart
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/jsr294-modularity-observer/attachments/20090418/d403e13f/attachment.html>
More information about the jsr294-modularity-observer
mailing list