This discussion is archived
2 Replies Latest reply: Oct 25, 2012 3:57 AM by RavagliVirgilio RSS

Closing URLClassLoader seemingly discards runtime annotations

RavagliVirgilio Newbie
Currently Being Moderated
I'm working with JDK 1.7, on Windows 7.
I created the class num.Complex, in Uti.jar; and created an annotation, Remark, too, with policy = RUNTIME.
Then I added the annotation to Complex:
@Remark(comment="doesn't matter")
public class Complex....

From another application:
URL[] urls = { new URL("file:/C:/LibJar/Uti.jar") };
URLClassLoader loader = new URLClassLoader(urls);
Class cls = loader.loadClass("num.Complex");

....reflection code to show constructors, methods and fields: it works fine....

Annotation[] notes = cls.getAnnotations();

at this very point, I find NO annotations at all.
If I don't close the loader, I find the annotation.

Is it correct ? why annotations are treated differently ?

thanks in advance


  • Correct Answers - 10 points
  • Helpful Answers - 5 points