I'm being fed a Class<?>
from a 3rd party .jar pertaining to a method's parameter type. I need to take different actions based on what this Class<?>
actually is.
If it is anything that subclass java.lang.Number
(such as Integer
, or BigDecimal
) I need to take a special course of action.
I can't use instanceof
. And I'm afraid that if I use:
Class<?> someClass = getParameterTypeFrom3rdParty();
if(someClass == Number.class)
// ...
Then it will execute if Class<?>
is only a Number
. How can I incorporate inheritance into the mix so I get all of Number
's subtypes?
Thanks in advance!
Number.class.isAssignableFrom(someClass);
That should do the trick
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With