How can I determine whether a Java class is abstract by reflection

JavaClassAbstract

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

Solution 2 - Java

Class myClass = myJar.load("classname");
bool test = Modifier.isAbstract(myClass.getModifiers());

Solution 3 - Java

public static boolean isInstantiable(Class<?> clz) {
	if(clz.isPrimitive() || Modifier.isAbstract( clz.getModifiers()) ||clz.isInterface()  || clz.isArray() || String.class.getName().equals(clz.getName()) || Integer.class.getName().equals(clz.getName())){
		return false;
	}
	return true;
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionpeter.murray.rustView Question on Stackoverflow
Solution 1 - JavasethView Answer on Stackoverflow
Solution 2 - JavaStoborView Answer on Stackoverflow
Solution 3 - JavaAbdushkur AblimitView Answer on Stackoverflow