Check if a class exists in the Java classpath without starting its static initializer?

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 initializer block "Foo" is started. Is there a way to determine if the class "my.package.Foo" is in the classpath without starting its static initializer?

+57
java class classloader
Aug 12 '10 at
source share
1 answer

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

javoc link

+77
Aug 12 '10 at 10:09
source share



All Articles