Adding a type for a variable

118 views Asked by At

jcodemodel makes it possible to add private attributes by doing something like:

JFieldVar quantity = jc.field(JMod.PRIVATE, Integer.class, "myAtt");

However, what happens instead of using a class from the JDK you are using a class that won't be on the classpath at the time you invoke field API?

All you know is the class name as a String, you don't have that class on your classpath - someone else is generating it.

1

There are 1 answers

0
johnluetke On

All JCodeModel will do is generate the .java file for you. When you go to compile the the generated file, and a required class is not on the classpath, you will get a compilation error. Similarly, if the class is not present at runtime, a NoClassDefFound exception will be thrown by the classloader when the class is first referenced.