1

instanceof shows if an instance is from class C or a subclass of C.

Is there a way to make sure that an instance is not a subclass?

luk2302
  • 55,258
  • 23
  • 97
  • 137
Christoph S.
  • 585
  • 3
  • 16

1 Answers1

2

In that case use getClass() and compare it with the desired class:

boolean sameClass = someObject.getClass() == YourTargetClass.class;
luk2302
  • 55,258
  • 23
  • 97
  • 137