Is there a way programmitcally to tell if a Java class is abstract? (Other than trying to instantiate and catching the error) Thanks!
Asked
Active
Viewed 4,333 times
14
-
1Why would you care? (A failure to construct an instance may be for a number of reasons.) – Tom Hawtin - tackline Feb 12 '10 at 18:37
-
Possible duplicate of [How can I determine whether a Java class is abstract by reflection](http://stackoverflow.com/questions/1072890/how-can-i-determine-whether-a-java-class-is-abstract-by-reflection) – Jasper de Vries Aug 17 '16 at 15:26
1 Answers
25
You can use reflection:
if (Modifier.isAbstract(FooBar.class.getModifiers())) {
// ...
}

C. K. Young
- 219,335
- 46
- 382
- 435
-
Same answer (+interesting link) here : http://stackoverflow.com/questions/1072890/how-can-i-determine-whether-a-java-class-is-abstract-by-reflection – Benj Aug 05 '15 at 13:33