Subclassing abstract property with defined class, e.g myprop@char, throws an error

조회 수: 3 (최근 30일)
Suppose I have a superclass that I want to use to create an interface:
classdef foo
properties(Abstract)
String@char
end
end
the property is set to char (I could also add vector, i.e. String@char vector , with same consequences).
Now, the concrete class that sets a default to that property is:
classdef subfoo < foo
properties
String = 'something';
end
end
However, in the command line:
>> subfoo
Error using subfoo
The property 'String' restriction defined in class 'subfoo' must match the property definition
in base class 'foo'.
I am forced to declare the property as String@char even in subfoo .
What's the rationale behind this?
PS. I am using an undocumented feature in OO of properties declaration, more details on http://undocumentedmatlab.com/blog/setting-class-property-types.

답변 (1개)

Igor Varfolomeev
Igor Varfolomeev 2016년 3월 29일
By the way, it's still the same in R2016a - even after this syntax feature was officially introduced.
Probably, they treat it like other qualifiers, like "Constant". From some points of view, it sounds reasonable, that you cannot define property as Constant, and then re-define it as non-Constant in an inherited class.
This limitation, most probably, is a result of the same built-in "do not re-define qualifiers" principle. And, personally, I find it much more inconvenient....

카테고리

Help CenterFile Exchange에서 Class Introspection and Metadata에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by