Suppose I have a user defined MATLAB class like this:
function obj = A()
obj.property1 = 1;
obj.property2 = 2;
And then instantiate class A like this:
Then I instantiate a Java collection in MATLAB like this:
list = java.util.ArrayList();
Then I encapsulate that instance of class A into a cell and add it into that ArrayList like this:
It has to be encapsulated into a cell for it to work for some obvious reasons.
Then I retrieve that instance of class A back from the ArrayList like this:
What I get in b is
I have read the section on handling values returned Java values and I infer that there is no way to recover or cast that returned java.lang.Object to a type of class A.
Or is there? I am trying to shove in user-defined MATLAB types into Java collections because MATLAB does not offer the richness of collection manipulations that Java does. The above would have worked if I used one of the built in MATLAB types, but my interest is specific to user-defined MATLAB types. I suppose another way would be to create a Java class that implements the functionality of my user-defined MATLAB Class and store that into the a Java collection instantiated within MATLAB.