MATLAB: Checking dataType instead typecast at property or argument validation

argument validationmeta.validationoopproperty validation

Hello, I would like to use property/ argument validation in a different way. I would like to prevent the assignment of other types as the specified meta.Validation.Class.
As an example:
I've the following class
classdef TestPropertyValidation
properties
myProperty double {mustBeNumeric}
end
methods
function obj = TestPropertyValidation(stringVal)
obj.myProperty = stringVal;
end
end
end
If I pass now …
>> TestPropertyValidation("Hello")
ans =
TestPropertyValidation with properties:
myProperty: NaN
I guess because of the conversion:
>> double("Hello")
ans =
NaN
>> isnumeric(NaN)
ans =
logical
1
But I like the way specifying conditions for properties. And I would like to use it in a bigger project. There we have to make sure no uncontrolled conversions happen between object constructor calls with lots of paramters passed to constructors and methods. I would like to prevent that for example 1+'1' := 50 operations can happen because of a misplaced method parameter for example.
I know I can use the ValidatorFunctions to prevent that for example a character is passed instead a double but only if I don't state the desired class, for example 'double' to don't have a conversion. It would be very nice having the type check and afterwards the validatorFunctions for further conditions to values. Is there a way to change the validation of properties and arguments to have a validation of the class instead of a conversion at validation order step 1.
Thank you.

Best Answer

There's no way to do this with validators in R2019b and the datatype coercion will always happen. You can use a set.property setter method to type check new values.