Imagine, I want to write a useless method called: isInstanceof that returns a boolean.
I was thinking about it. But I do not get out. An instanceof has to be used like:
[object] instanceof [a classname]
// I was thinking about something like this
public static boolean isInstanceof(Object obj, /*magic for the second param*/)
{
return obj instanceof /*the magical second param*/
}
But how can I make an parameter for [a classname]? Is there a way to do this without the method isInstance(Class cls) from java.lang.Class?
Thanks
Hehe, yes. Use isAssignableFrom(Class) from
Class. Not only is it notisInstance(Class), it also matches the way theinstanceofoperator works more closely. 🙂Other than that, no, there’s not much you can do without those methods from
Class.