Documentation Center

  • Trial Software
  • Product Updates

meta.class

meta.class class describes MATLAB classes

Description

Instances of the meta.class class contains information about MATLAB® classes. The read/write properties of the meta.class class correspond to class attributes and are set only from within class definitions on the classdef line. You can query the read–only properties of the meta.class object to obtain information that is specified syntactically by the class (for example, to obtain the name of the class).

You cannot instantiate a meta.class object directly. You can construct a meta.class object from an instance of a class or using the class name:

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

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

  • fromName — static method returns a meta.class object representing the named class.

For example, the metaclass function returns the meta.class object representing MyClass.

ob = MyClass;
obmeta = metaclass(ob);
obmeta.Name
ans =
MyClass

You can use the class name to obtain the meta.class object:

obmeta = ?MyClass;

You can also use the fromName static method:

obmeta = meta.class.fromName('MyClass');

Properties

PropertyPurpose

Abstract attribute, default = false

If true, this class is an abstract class (cannot be instantiated).

See Defining Abstract Classes for more information.

AllowedSubclasses attribute, write only from classdef statement

List classes that can subclass this class. Specify subclasses as meta.class objects in the form:

  • A single meta.class object

  • A cell array of meta.class objects

Specify meta.class objects using the ?ClassName syntax only.

ConstructOnLoad attribute, default = false

If true, MATLAB calls the class constructor automatically when loading an object from a MAT-file. Therefore, the construction must be implemented so that calling it with no arguments does not produce an error.

See Tips for Saving and Loading

ContainingPackage read only

A meta.package object describing the package within which this class is contained, or an empty object if this class is not in a package.

See Packages Create Namespaces.

Description read onlyCurrently not used
DetailedDescription read onlyCurrently not used
Enumeration attribute, default = false

If true, this class is an enumeration class. See Working with Enumerations.

EventList read only

An array of meta.event objects describing each event defined by this class, including all inherited events.

See Events.

Events read only

Use EventList instead

A cell array of meta.event objects describing each event defined by this class, including all inherited events.

EnumerationMemberList

An array of meta.EnumeratedValue objects describing the member names defined by an enumeration class.

See Enumerations for more information on enumeration classes.

EnumeratedValues read only

Use EnumeratedMemberList instead

A cell array of meta.EnumeratedValue objects describing the member names defined by an enumeration class.

See Enumerations for more information on enumeration classes.

Hidden attribute, default = falseIf set to true, the class does not appear in the output of MATLAB commands or tools that display class names.
InferiorClasses attribute, default = {}

A cell array of meta.class objects defining the precedence of classes represented by the list as inferior to this class.

See Class Precedence

MethodList read only

An array of meta.method objects describing each method defined by this class, including all inherited public and protected methods.

See How to Use Methods.

Methods read only

Use MethodList instead

A cell array of meta.method objects describing each method defined by this class, including all inherited public and protected methods.

Name read onlyName of the class associated with this meta.class object (char array)
PropertyList read only

An array of meta.property objects describing each property defined by this class, including all inherited public and protected properties.

See Properties.

Properties read only

Use PropertyList instead

A cell array of meta.property objects describing each property defined by this class, including all inherited public and protected properties.

See Properties.

Sealed attribute, default = false

If true, the class cannot be subclassed.

SuperClassList read only

An array of meta.class objects describing each direct superclass from which this class is derived.

See Creating Subclasses — Syntax and Techniques.

SuperClasses read only

Use SuperClassList instead

A cell array of meta.class objects describing each direct superclass from which this class is derived.

Methods

MethodPurpose
fromNameReturns the meta.class object associated with the specified class name.
tf = eq(Cls)Equality function (a == b). Use to test if two variables refer to equal classes (classes that contain exactly the same list of elements).
tf = ne(Cls)Not equal function (a ~= b). Use to test if two variables refer to different meta–classes.
tf = lt(ClsA,ClsB)Less than function (ClsA < ClsB). Use to determine if ClsA is a strict subclass of ClsB (i.e., a strict subclass means ClsX < ClsX is false).
tf = le(ClsA,ClsB)Less than or equal to function (ClsA <= ClsB). Use to determine if ClsA is a subclass of ClsB.
tf = gt(ClsA,ClsB)Greater than function (ClsB > ClsA). Use to determine if ClsB is a strict superclass of ClsA (i.e., a strict superclass means ClsX > ClsX is false).
tf = ge(ClsA,ClsB)Greater than or equal to function (ClsB >= ClsA). Use to determine if ClsB is a superclass of ClsA.

Events

EventPurpose

InstanceCreated

If the class is a handle class, this event occurs every time a new instance of this handle class is created, including new instances of any subclasses. The event occurs immediately after all constructor functions finish executing.

InstanceDestroyed

If the class is a handle class, this event occurs every time an instance of this handle class is destroyed, including all subclasses. The event occurs immediately before any destructor functions execute.

Examples

Find property attributes using the handle class findobj method and the audioplayer meta.class object. Determine if a class defines the property named SampleRate and does it have public set access.

mc = ?audioplayer;
mp = findobj(mc.PropertyList,'Name','SampleRate');
strcmp(mp.SetAccess,'public')
   ...

See Also

| | | |

Was this topic helpful?