Cannot retrieve argument list from a class constructor with arguments checking
Show older comments
I've the following class:
classdef Main
%MAIN Summary of this class goes here
% Detailed explanation goes here
properties (Access = private)
logger;
options;
end
methods (Access = public)
function this = Main(options, logger)
%MAIN Construct an instance of this class
% Detailed explanation goes here
this.logger = logger;
this.options = options;
end
end
end
I want to retrieve the list of arguments of the constructor, and I do this way:
c = ?Main;
c.MethodList.InputNames
I obtain
ans =
2×1 cell array
{'options'}
{'logger' }
And everything is ok.
Now I also want to add a check on the arguments, to be sure that they are of the correct type. So I've updated my class this way:
classdef Main% < App.Interfaces.Component
%MAIN Summary of this class goes here
% Detailed explanation goes here
properties (Access = private)
logger;
options;
end
methods (Access = public)
function this = Main(options, logger)
%MAIN Construct an instance of this class
% Detailed explanation goes here
arguments
options (1, 1) App.Options
logger (1, 1) App.Logger
end
this.logger = logger;
this.options = options;
end
end
end
But now, If I try to re-run the code for retrieving the arguments, I obtain
ans =
1×1 cell array
{'varargin'}
Adding the check does not allow me to retrieve the arguments anymore, because I obtain only varargin.
Why this happens? Is there a way to add the arguments check and retrieve correctly the names of the constructor arguments anyway?
Accepted Answer
More Answers (0)
Categories
Find more on Historical Contests 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!