views:

85

answers:

1

If I use

   try {
      Class.forName("my.package.Foo");
      // it exists on the classpath
   } catch(ClassNotFoundException e) {
      // it does not exist on the classpath
   }

the static initializer block of "Foo" is kicked off. Is there a way to determine whether a class "my.package.Foo" is on the classpath without kicking off its static initializer?

+8  A: 

Try the method forName(String name, boolean initialize, ClassLoader loader) of Class and set the param "initialize" to false.

André
Should work. According to the API: The class is initialized only if the initialize parameter is true and if it has not been initialized earlier.
aioobe