Main Content

Enumeration Class Restrictions

Enumeration classes restrict certain aspects of their use and definition:

  • Enumeration classes are implicitly Sealed. You cannot define a subclass of an enumeration class because doing so would expand the set.

  • The properties of value-based enumeration classes are immutable. Only the constructor can assign property values. MATLAB® implicitly defines the SetAccess attributes of all properties defined by value-based enumeration classes as immutable. You cannot set the SetAccess attribute to any other value.

  • All properties inherited by a value-based enumeration class that are not defined as Constant must have immutable SetAccess.

  • The properties of handle-based enumeration classes are mutable. You can set property values on instances of the enumeration class. See Mutable Handle vs. Immutable Value Enumeration Members.

  • An enumeration member cannot have the same name as a property, method, or event defined by the same class or inherited from a superclass. For example, an enumeration class that inherits from a built-in numeric superclass inherits the full method from the superclass, so "full" is not a valid member name.

  • Enumerations do not support colon (a:b) operations. For example, FlowRate.Low:FlowRate.High causes an error even if the FlowRate class derives from a numeric superclass.

  • Classes that define enumerations cannot restrict properties of the same class to an enumeration type. Create a separate enumeration class to restrict property values to an enumeration. For information on restricting property values, see Example of Restricted Property.

  • If the primary enumeration member sets the Hidden attribute, then the secondary member (one with the same underlying value) must also set the Hidden attribute. For more information, see Hide Enumeration Members.

Related Topics