Class metadata is information about class definitions that is available from various metaclasses objects. Use metaclass objects to obtain information without having to create instances of the class. Metadata enables the programmatic inspection of classes. Each metaclass has properties, methods, and events that contain information about the class or class component it describes.
All class components have an associated metaclass, which you
access from the meta.class
object. For example,
create the meta.class
object for the matlab.mixin.Copyable
class:
mc = ?matlab.mixin.Copyable
mc = class with properties: Name: 'matlab.mixin.Copyable' Description: 'Implement copy method for handle objects in MA...' DetailedDescription: '' Hidden: 0 Sealed: 0 Abstract: 1 Enumeration: 0 ConstructOnLoad: 1 HandleCompatible: 1 InferiorClasses: {0x1 cell} ContainingPackage: [1x1 meta.package] PropertyList: [0x1 meta.property] MethodList: [19x1 meta.method] EventList: [1x1 meta.event] EnumerationMemberList: [0x1 meta.EnumeratedValue] SuperclassList: [1x1 meta.class]
The meta
package contains metaclasses that
describe the definition of classes and class components. The class
name indicates the component described by the metaclass. For example,
each class property has a meta.property associated with it. Attributes
defined for class components correspond to properties in the respective
metaclass object.
meta.package
—
Access from meta.class
ContainingPackage
property.
meta.class
—
Create from class name or class object using metaclass
function
or ?
operator.
meta.property
—
Access from meta.class
PropertyList
property.
meta.DynamicProperty
—
Obtain from the addprop
method.
meta.method
—
Access from meta.class
MethodList
property.
meta.event
—
Access from meta.class
EventList
property.
meta.EnumeratedValue
—
Access from meta.class
EnumerationMemberListList
property.
You cannot instantiate metaclasses directly by calling the respective class constructor. Create metaclass objects from class instances or from the class name.
?
—
Returns a ClassName
meta.class
object for the named class.
Use meta.class.fromName
with class names stored
as characters in variables.
meta.class.fromName('
—
returns the ClassName
')meta.class
object for the named class
(meta.class.fromName
is a meta.class
method).
metaclass(obj)
— Returns
a metaclass object for the class instance (metaclass
)
Create meta.class
object from class name
using the ?
operator:
mc = ?MyClass;
Create meta.class
object from class name
using the fromName
method:
mc = meta.class.fromName('MyClass');
Create meta.class
object from class instance
obj = MyClass; mc = metaclass(obj);
The metaclass
function returns the meta.class
object
(that is, an object of the meta.class
class). You
can obtain other metaclass objects (meta.property
, meta.method
,
and so on) from the meta.class
object.
Note
Metaclass is a term used here to refer to all the classes in
the meta
package. meta.class
is
a class in the meta
package whose instances contain
information about MATLAB® classes. Metadata is information about
classes contained in metaclasses.
When you change a class definition, MATLAB reloads the class definition. If instances of the class exist, MATLAB updates those objects according to the new definition.
However, MATLAB does not update existing metaclass objects to the new class definition. If you change a class definition while metaclass objects of that class exist, MATLAB deletes the metaclass objects and their handles become invalid. You must create a new metaclass object after updating the class.
For information on how to modify and reload classes, see Automatic Updates for Modified Classes.