How would I write and call the method boolean doInstanceof(...) which takes an Object o and a type t and returns true if o is an instance of t, returns false otherwise.
Something like:
boolean doInstanceof(Object o, type t)
{
return o instanceof t;
}
//called like
boolean isInstance = doInstanceof(new MyClass(), MyClass.type())
You can use
Classand itsisInstancemethod:Mind you, that’s only replacing one method call for another – you might as well call
Class.isInstancedirectly:(I’m assuming that in reality you don’t know the class at compile-time, otherwise you should just use
instanceofof course.)