-
Notifications
You must be signed in to change notification settings - Fork 0
Description
I'm building most of my classes in MSch as Matlab classdef wrappers around the corresponding Java objects. The pattern looks like this:
classdef Identity < handle
properties (SetAccess = private, Hidden = true)
% The underlying com.jcraft.jsch.Identity Java object
j
end
properties (Dependent)
name
algorithmName
isEncrypted
end
methods
function this = Identity(jIdentity)
if nargin == 0
return
end
mustBeA(jIdentity, 'com.jcraft.jsch.Identity');
this.j = jIdentity;
end
function out = get.name(this)
out = string(this.j.getName);
end
function out = get.algorithmName(this)
out = string(this.j.getAlgName);
end
function out = get.isEncrypted(this)
out = this.j.isEncrypted;
end
end
endThat j property is intended to hold the wrapped Java object.
But it's necessary to allow for Matlab objects that have an empty j value: it's not possible in all cases to construct appropriate default underlying Java object values efficiently or at all. And we need to be able to construct "null" or "uninitialized" Matlab objects, for the cases when we need to pre-allocate an array (e.g. idents = repmat(msch.Identity, [1 n]);) or construct a default object instance to conform to declarative type constraint requirements on properties in other objects.
For these "uninitialized" objects, j is [], so the get.XXX(this) methods will fail, because they try to do a method call on [], which is a double that doesn't support those methods. And the default object disp()/display() for scalar objects will call those methods, because it tries to call those methods. What happens is that those properties appear to not exist in the object display (it doesn't throw an error).
Should I do something to handle this more gracefully?
- Custom
disp()that displays " (uninitialized)" for uninitialized objects? - Alter the
get.*methods to return default values whenjis empty?
I think this is just a cosmetic issue, since display doesn't actually raise an error.