I have a class that inherits from multiple superclasses, and I would like to get the methods that the class has. Naively using methods()
returns methods from the class I'm working with as well as superclass methods, but I'm not interested in the superclass methods.
Any idea how to do this? I couldn't find anything in MATLAB documentation.
Thanks!
methodsview( packagename. classname ) displays information about the methods in the class classname . If the class is in a package, include packagename . If classname is a MATLAB® or Java® class, methodsview lists only public methods, including those methods inherited from superclasses.
Subclass methods can call superclass methods if both methods have the same name. From the subclass, reference the method name and superclass name with the @ symbol.
To call a static method, prefix the method name with the class name so that MATLAB can determine what class defines the method. Call staticMethod using the syntax classname . methodname : r = MyClass.
When you create a subclass derived from multiple superclasses, the subclass inherits the properties, methods, and events defined by all specified superclasses. If more than one superclass defines a property, method, or event having the same name, there must be an unambiguous resolution to the multiple definitions.
If your subclass doesn't reimplement any of the methods of the superclasses (or if you're fine with ignoring reimplemented methods), you can use the functions METHODS and SUPERCLASSES to find a list of subclass methods that aren't also methods of any of the superclasses. For example:
>> obj = 'hgsetget'; %# A sample class name
>> supClasses = superclasses(obj)
supClasses =
'handle' %# Just one superclass, but what follows should handle more
>> supMethods = cellfun(@methods,supClasses,... %# Find methods of superclasses
'UniformOutput',false);
>> supMethods = unique(vertcat(supMethods{:})); %# Get a unique list of
%# superclass methods
>> subMethods = setdiff(methods(obj),supMethods) %# Find methods unique to the
%# subclass
subMethods =
'get'
'getdisp'
'set'
'setdisp'
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