On 11/16/2015 3:19 AM, Philippe Marschall wrote:
On 12.11.15 14:50, Stephen Colebourne wrote:
My understanding of annotations today is that annotations are not
required at runtime. ie. if an annotation is placed into a class at
compile time but the .class file for the annotation is not available
on the runtime classpath. then there is no error.

Does this change in any way with modules?

My specific case is wrt @ConstructorProperties which is in java.beans.
In 9, a user may run my software without the java.beans module. Can I
safely assume that if the annotation is available on the compile
module path but not the runtime module path, everything will be OK
(ie. no error)?

My understanding is that you can't have optional dependencies. So if you
have @ConstructorProperties in your source you also need to have a
java.desktop module dependency in your module-info.java. If your library
is in the module path the java.desktop module then it needs to be
present at runtime.

The only option you have is to make your jar not a modular jar by one of
those:
  - not providing a module-info.class
  - not putting your module in the module path

This is all true -- a static reference to java.beans.ConstructorProperties necessitates a dependency on java.desktop at compile time.

The reason for my stripped-down answer was that Stephen phrased the question using some rather abstract language -- "an annotation is placed into a class", "a user may run my software ...". This made me think something clever was going on -- for example, the user's dependency on java.desktop is factored out and Stephen's software receives a Class object for java.beans.ConstructorProperties from someone else.

Alex

Reply via email to