14

Is there a way programmitcally to tell if a Java class is abstract? (Other than trying to instantiate and catching the error) Thanks!

jim
  • 143
  • 1
  • 4
  • 1
    Why 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 Answers1

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