Main Content

matlab.mixin.Heterogeneous.getDefaultScalarElement

Class:matlab.mixin.Heterogeneous
Package:matlab.mixin

Return default object for heterogeneous array operations

Syntax

defaultObject = getDefaultScalarElement

Description

defaultObject= getDefaultScalarElementreturns 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.getDefaultScalarElementmust return an instance of another member of the heterogeneous hierarchy.

The implementation ofgetDefaultScalarElementinherited from thematlab.mixin.Heterogeneousclass returns an instance of the root class. If the root class is abstract, you must implementgetDefaultScalarElementin the root class to return a default object. For more information, seeRoot Class.

MATLAB®calls thegetDefaultScalarElementmethod when requiring a default object. For more information on heterogeneous arrays and default objects, seematlab.mixin.Heterogeneous.

Output Arguments

defaultObject

The default object for heterogeneous array operations.

Attributes

Static true
Access Protected
Sealed truenot required

To learn about attributes of methods, seeMethod Attributes.

Examples

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. TheFinancialObjectsclass definition includes an override of thegetDefaultScalarElementmethod which returns an instance of theAssetsclass as the default object.

The root class can override thegetDefaultScalarElementmethod that is defined inmatlab.mixin.Heterogeneousclass and return anAssetsobject as the default object.

classdefFinancialObjects < matlab.mixin.Heterogeneousmethods(Abstract) val = determineCurrentValue(obj)endmethods(Static, Sealed, Access = protected)functiondefault_object = getDefaultScalarElement default_object = Assets;endendend

More About

expand all

Tips

  • OverridegetDefaultScalarElementonly if the root class is not suitable as a default object.

  • OverridegetDefaultScalarElementonly in the root class of the heterogeneous hierarchy.

  • getDefaultScalarElementmust 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 bygetDefaultScalarElementis not scalar or is not an instance of a class that is a valid member of the hierarchy.