views:

1051

answers:

2

I am interating through classes in a Jar file and wish to find those which are not abstract. I can solve this by instantiating the classes and trapping InstantiationException but that has a performance hit as some classes have heavy startup. I can't find anything obviously like isAbstract() in the Class.java docs. (many thanks for the rapid replies I got last time)

+7  A: 

It'll have abstract as one of its modifiers when you call getModifiers() on the class object.

This link should help.

 Modifier.isAbstract( class.getModifiers() );

Also:

http://java.sun.com/javase/6/docs/api/java/lang/reflect/Modifier.html

http://java.sun.com/javase/6/docs/api/java/lang/Class.html#getModifiers()

seth
+3  A: 
Class myClass = myJar.load("classname");
bool test = Modifiers.isAbstract(myClass.getModifiers());
Stobor
Also, what seth said. :)
Stobor
Great minds think alike.
seth
just to check, that should be "Modifier"
peter.murray.rust