Reputation: 1186
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?
Upvotes: 4
Views: 401
Reputation: 1755
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.
Upvotes: 7