meta.method class
Package: meta
Superclasses: meta.MetaData
Describe MATLAB 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 MethodList
property of a
meta.class
object. MethodList
contains an array of
meta.method
objects, one for each class method.
For example, in this 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
Name
— Method name
character vector
Method name returned as a character vector.
Description
— Short description of method
character vector
Short description of the method, returned as a character vector. For user-defined classes, the text for this property comes from code comments in the method definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your class methods, see Custom Help Text.
DetailedDescription
— Detailed description of method
character vector
Detailed description of the method, returned as a character vector. For user-defined classes, the text for this property comes from code comments in the method definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your class methods, see Custom Help Text.
Access
— Access level of method
public
(default) | protected
| private
| one or more meta.class
objects
The access level of the method, specified as:
public
— unrestricted accessprotected
— access from methods in class or subclassesprivate
— 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 asprivate
access.
Data Types: enumerated
| meta.class
Static
— Is method static
false
(default) | true
Is the 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.
for more information, see Static Methods.
Abstract
— Is method abstract
false
(default) | true
Is the 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.
Sealed
— Can this method be overridden
false
(default) | true
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.
Hidden
— Is this method hidden
false
(default) | true
Is this method hidden, returned as logical true
or
false
. When false
, the method name appears in
the list of methods displayed using the methods
or
methodsview
command. When set to true
, the
method name is not included in these listings or when displaying the object in the
command window.
InputNames
— Names of input arguments
character vector | cell array of character vectors
Names of the input arguments used in the function signature, returned as a character vector or a cell array of character vectors.
OutputName
— Names of output arguments
character vector | cell array of character vectors
Names of the output arguments used in the function signature, returned as a character vector or cell array of character vectors.
DefiningClass
— Class that defines method
meta.class
object
Class that defines the method, returned as a 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.
Examples
Use Introspection to Get Information About Method
Use meta.method
to get information about a class method of the IntrospectionExample
class.
Code for IntrospectionExample
classdef IntrospectionExample % IntrospectionExample Performs basic functions on two numbers % This class can return the sum and product of its two properties. properties % a First property % First of two numeric properties a {mustBeNumeric} = 0 % b Second property % Second of two numeric properties b {mustBeNumeric} = 0 end methods function sum = addNumbers(obj) % addNumbers Sum the properties % Finds the sum of properties a and b. sum = obj.a + obj.b; end function prod = multNumbers(obj) % multNumbers Multiply the properties % Finds the product of properties a and b. prod = obj.a*obj.b; end end end
Create and Inspect a Metaclass Instance
Create a metaclass instance for IntrospectionExample
. Access the first method in the MethodList
property of mc
to get a meta.method
object.
mc = ?IntrospectionExample; mc.MethodList(1)
ans = method with properties: Name: 'multNumbers' Description: 'Multiply the properties' DetailedDescription: ' Finds the product of properties a and b.' Access: 'public' Static: 0 Abstract: 0 Sealed: 0 ExplicitConversion: 0 Hidden: 0 InputNames: {'obj'} OutputNames: {'prod'} DefiningClass: [1x1 meta.class]
Version History
Introduced in R2008aR2022a: Description
and DetailedDescription
properties contain text from code comments
For user-defined classes with appropriately placed code comments, the
Description
and DetailedDescription
properties
are populated with text pulled from those comments. For more information on how to use code
comments to store custom help text for user-defined classes, see Custom Help Text.
See Also
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)