Class Unexpected Behaviour with Properties and Type Casting
Show older comments
Hello Community,
Is this the expected behavior when having a property in a class that is type declared and then re-assigned to a different type?
classdef Blah
properties
meh char = '';
end
methods
function obj = Blah()
obj.meh = {'Bleah!', 'Bleah, again'};
end
end
end
Here is the screenshot of the result of the class instantiation:

Shouldn't this code produce at least a runtime error when meh is assigned to a cell object instead of forcing this automatic typecasting?
This gives an error (expected)
Is this my old version on matlab2018b that works in this confusing way?
It defeats the purpose of declaring the type because accidental/wrong assignments to different types go undetected.
Accepted Answer
More Answers (0)
Categories
Find more on Functions 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!