Main Content

meta.class class

Package: meta
Superclasses: meta.MetaData

Describe MATLAB class

Description

The meta.class class provides a way to get descriptive information about MATLAB® classes. By creating a meta.class object for a specific class, you can get information about the class definition.

Some properties of a meta.class object contain the values of class attributes defined in the corresponding MATLAB class. Query these properties for information that is specified syntactically by the class definition on the classdef line.

Other properties contain lists of properties, methods, and events defined by the class, as well as other information about how the class is defined.

You cannot set the values of meta.class object properties. You can only query the properties.

Create a meta.class object from an instance of a class or using the class name using these options:

  • metaclass(obj) — returns a meta.class object representing the object passed as an argument.

  • ?ClassName — returns a meta.class object representing the named class.

  • meta.class.fromName('ClassName') — static method returns a meta.class object representing the named class.

You cannot instantiate a meta.class object directly by calling its constructor.

The meta.class class is a handle class.

Class Attributes

Abstract
true
HandleCompatible
true

For information on class attributes, see Class Attributes.

Properties

expand all

Name of the class, returned as a character vector. The name returned by this property includes the class package.

Data Types: char

Short description of the class, returned as a character vector. For user-defined classes, the text for this property comes from comments in the class definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your classes, see Custom Help Text.

Detailed description of the class, returned as a character vector. For user-defined classes, the text for this property comes from comments in the class definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your classes, see Custom Help Text.

Is class hidden from inspection tools, returned as logical true or false. When set to true, the class does not appear in the output of MATLAB commands or tools that display class names. However, you can access the class programmatically.

Data Types: logical

Can class be subclassed, returned as a logical value. If Sealed is true, this class cannot be subclassed.

Data Types: logical

Value of class abstract attribute, returned as a logical value. The value of this property is true if the class or any property or method has its Abstract attribute set to true. For information on abstract classes, see Abstract Classes and Class Members.

Data Types: logical

Is class an enumeration class, returned as a logical value. If true, this class is an enumeration class. For more information about enumeration classes, see Define Enumeration Classes.

Data Types: logical

Call constructor on load, returned as a logical value. If true, MATLAB calls the class constructor automatically when loading an object from a MAT-file. To enable ConstructOnLoad, the constructor must support being called with no input arguments. For more information, see Save and Load Process for Objects.

Data Types: logical

Is class handle compatible, returned as a logical value. If true, this class is a handle-compatible class. For more information about handle-compatible classes, see Handle Compatible Classes.

Data Types: logical

Classes specified as inferior to this class, returned as a cell array of meta.class objects. For information on class precedence, see Class Precedence.

Data Types: meta.class

Package containing class, returned as a meta.package object. If the class is not in a package this property contains an empty meta.package object. For more information about packages, see Packages Create Namespaces.

Data Types: meta.package

List of aliases defined for the class, returned as a string array. The aliases are listed from oldest to newest.

Does class restrict subclassing, returned as a logical true or false. MATLAB sets this property to true when the class restricts subclassing by:

  • Setting the Sealed attribute to true

  • Specifying the classes that can subclass this class using the AllowedSubclasses attribute

For more information restricting subclassing, see Specify Allowed Subclasses.

Data Types: logical

Properties defined for the class, returned as an array of meta.property objects. The meta.property objects describe each property defined by this class, including all inherited public and protected properties. For more information on properties, see Properties.

Data Types: meta.property

Methods defined for the class, returned as an array of meta.method objects. The meta.method objects describe each method defined by this class, including inherited public and protected methods. For more information on methods, see Methods in Class Design.

Data Types: meta.method

Events defined for the class, including all inherited events, returned as an array of meta.event objects. Only handle classes can define events so this property is an empty meta.event object for value classes. All handle classes inherit the ObjectBeingDestroyed event. For more information about events, see Events.

Data Types: meta.event

Name and hidden status for enumeration members, returned as an array of meta.EnumeratedValue objects. Access the Name and Hidden properties of the corresponding member meta.EnumeratedValue object to obtain information. For more information, see Enumerations.

Data Types: meta.EnumeratedValue

Direct superclasses of this class, returned as an array of meta.class objects. The meta.class objects describe each direct superclass from which this class derives. For more information on subclassing, see Subclass Definition.

Data Types: meta.class

Methods

expand all

Events

Event NameTriggerEvent DataEvent Attributes
InstanceCreated

This event occurs every time an instance of the class described by the meta.class is created.

The event occurs immediately after all constructor functions finish executing.

event.ClassInstanceEvent

NotifyAccess: private

ListenAccess: public

InstanceDestroyed

This event occurs every time an instance of the class described by the meta.class is destroyed.

The event occurs immediately before any destructor functions execute.

event.ClassInstanceEvent

NotifyAccess: private

ListenAccess: public

Examples

collapse all

Use introspection to get inheritance information about 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.

mc = ?IntrospectionExample
mc = 
  class with properties:

                     Name: 'IntrospectionExample'
              Description: 'Performs basic functions on two numbers'
      DetailedDescription: '  This class can return the sum and product of its two properties.'
                   Hidden: 0
                   Sealed: 0
                 Abstract: 0
              Enumeration: 0
          ConstructOnLoad: 0
         HandleCompatible: 0
          InferiorClasses: {0x1 cell}
        ContainingPackage: [0x0 meta.package]
                  Aliases: [0x1 string]
     RestrictsSubclassing: 0
             PropertyList: [2x1 meta.property]
               MethodList: [4x1 meta.method]
                EventList: [0x1 meta.event]
    EnumerationMemberList: [0x1 meta.EnumeratedValue]
           SuperclassList: [0x1 meta.class]

The property summary for IntrospectionExample shows there are four methods described in the MethodList property. Access the MethodList property of mc and display the names of all four class methods.

for i = 1:4
mc.MethodList(i).Name
end
ans = 
'multNumbers'
ans = 
'addNumbers'
ans = 
'IntrospectionExample'
ans = 
'empty'

Version History

Introduced in R2008a

expand all