I can use the Haxe Type Class to reflect an object's class e.g.
getClass<T> (o:T):Class<T>
Is there a way to check whether a given object implements an interface or is a subclass of another class?
You can use Std.is:
class Subclass extends OriginalClass implements IMyInterface {}
var myObj = new Subclass();
var isClass = Std.is(myObj, OriginalClass); // returns true
var isSubclass = Std.is(myObj, Subclass); // also returns true
var isInterface = Std.is(myObj, IMyInterface); // also returns true
Will return "true" if the second argument is the class of the object, one of its parent classes, or an interface it implements.
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