How to set object property to Abstract class
Show older comments
I am getting errors when I try to set an object property type to an Abstract class "matlab.mixin.Heterogeneous" as below:
classdef demoClass
properties
TestProperty matlab.mixin.Heterogeneous
end
methods
function obj = demoClass
% constructor that does not affect the property
end
end
end
The error I get is
>> demoClass
Error defining property 'TestProperty' of class 'demoClass'. Class matlab.mixin.Heterogeneous is abstract. Specify a default value for property TestProperty.
Accepted Answer
More Answers (1)
Jim Svensson
on 25 Aug 2021
13 votes
It is stupid Matlab language design. It should be normal to define a property to be an abstract class type. As long as it is empty (array with 0 elements) it is not a problem, and then only assign concrete sub-classes to the property.
Categories
Find more on Customize Object Display for Classes in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!