Class:matlab.mixin.Heterogeneous
Package:matlab.mixin
Return default object for heterogeneous array operations
defaultObject = getDefaultScalarElement
returns the default object for a heterogeneous hierarchy. Override this method if the root class is abstract or is not an appropriate default object for the classes in the heterogeneous hierarchy.defaultObject
= getDefaultScalarElementgetDefaultScalarElement
must return an instance of another member of the heterogeneous hierarchy.
The implementation ofgetDefaultScalarElement
inherited from thematlab.mixin.Heterogeneous
class returns an instance of the root class. If the root class is abstract, you must implementgetDefaultScalarElement
in the root class to return a default object. For more information, seeRoot Class.
MATLAB®calls thegetDefaultScalarElement
method when requiring a default object. For more information on heterogeneous arrays and default objects, seematlab.mixin.Heterogeneous
.
|
The default object for heterogeneous array operations. |
Static |
true |
Access |
Protected |
Sealed |
true not required |
To learn about attributes of methods, seeMethod Attributes.
This example describes a heterogeneous hierarchy with a root class (FinancialObjects
) that is an abstract class and cannot, therefore, be used for the default object. TheFinancialObjects
class definition includes an override of thegetDefaultScalarElement
method which returns an instance of theAssets
class as the default object.
The root class can override thegetDefaultScalarElement
method that is defined inmatlab.mixin.Heterogeneous
class and return anAssets
object as the default object.
classdefFinancialObjects < matlab.mixin.Heterogeneousmethods(Abstract) val = determineCurrentValue(obj)endmethods(Static, Sealed, Access = protected)functiondefault_object = getDefaultScalarElement default_object = Assets;endendend
OverridegetDefaultScalarElement
only if the root class is not suitable as a default object.
OverridegetDefaultScalarElement
only in the root class of the heterogeneous hierarchy.
getDefaultScalarElement
must return a scalar object.
getDefaultScalarElement
必须是一个静态方法与职业tected access. While not required by MATLAB, you can seal this method to prevent overriding by other classes.
MATLAB returns an error if the value returned bygetDefaultScalarElement
is not scalar or is not an instance of a class that is a valid member of the hierarchy.