Main Content

meta.method class

Package: meta
Superclasses: meta.MetaData

Information about class method

Description

The meta.method class provides information about the methods of MATLAB® classes. Properties of the meta.method class correspond to method attributes and other information that is specified syntactically in the class definition. All properties are read-only.

The meta.method class is a handle class.

Class Attributes

Abstract
true
ConstructOnLoad
true

For information on class attributes, see Class Attributes.

Creation

You cannot instantiate a meta.method object directly. Obtain a meta.method object from the meta.class MethodList property, which contains an array of meta.method objects, one for each class method.

For example, in the following code, replace ClassName with the name of the class whose methods you want to query:

mco = ?ClassName;
mlist = mco.MethodList;
mlist(1).Name; % name of first method in the list

To obtain a meta.class object from a class instance, use the metaclass function:

mco = metaclass(obj);

Properties

expand all

Method name returned as a character vector.

Data Types: char

Currently not used to collect information about the class from comments.

Data Types: char | string

Currently not used to collect information about the class from comments.

Data Types: char | string

The Access attribute controls what code has permission to call this method.

  • public — unrestricted access

  • protected — access from methods in class or subclasses

  • private — access by class methods only (not from subclasses)

  • List of classes that have access to this method, specified as meta.class objects in the form:

    • A single meta.class object

    • A cell array of meta.class objects. An empty cell array, {}, is the same as private access.

Example: method (Access = private)

Data Types: enumerated

Is method static, returned as logical true or false. When true, the method does not depend on an object of the class and does not require an object as input. Call static methods using the class name in place of the object:

classname.methodname()

Or with an instance of the class, like any method:

o.methodname()

See Static Methods

Example: method (Static)

Data Types: logical

Is method abstract, returned as logical true or false. If true, the method has no implementation, but the method has a syntax line that can include arguments. Subclasses implement the method following the abstract method signature.

  • The method does not contain function or end keywords, only the function syntax (e.g., [a,b] = myMethod(x,y))

  • Subclasses are not required to define the same number of input and output arguments. However, the syntax does indicate what subclasses are expected to implement.

  • The method can have comments after the syntax line.

Example: method (Abstract)

Data Types: logical

Can this method be overridden, returned as logical true or false. If true, the method cannot be redefined in a subclass. Attempting to define a method with the same name in a subclass causes an error.

Example: method (Sealed)

Data Types: logical

Is this method hidden, returned as logical true or false. When false, the method name shows in the list of methods displayed using the methods or methodsview commands. If set to true, the method name is not included in these listings or when displaying the object in the command window.

Data Types: logical

Names of the input arguments used in the function signature, returned as a character vector or a cell array of character vectors.

Data Types: char | cell

Names of the output arguments used in the function signature, returned as a character vector or cell array of character vectors.

Data Types: char | cell

Class defining this method, returned as the meta.class object representing the defining class. The defining class is always the most specific class from the perspective of the meta.method object. Therefore, if a subclass overrides an inherited method, then the defining class for the subclass meta.method object is the subclass. Similarly, the defining class for the superclass meta.method object is the superclass.

Data Types: meta.class

Examples

collapse all

Use meta.method data to get information about the copy method of the matlab.mixin.Copyable class.

mc =?matlab.mixin.Copyable;
copyInfo = findobj(mc.MethodList,"Name","copy")
copyInfo = 

  method with properties:

                   Name: 'copy'
            Description: ''
    DetailedDescription: ''
                 Access: 'public'
                 Static: 0
               Abstract: 0
                 Sealed: 1
                 Hidden: 0
             InputNames: {'rhs1'}
            OutputNames: {'lhs1'}
          DefiningClass: [1×1 meta.class]
Introduced in R2008a