I have an custom java object that returns an array of Thing
java objects. How can I convert and iterate over the returned array as java objects in matlab? Currently, it doesn't look like the returned array is being treated as java objects.
//Thing.java
public class Thing {
public int x,y,z;
public int[][] board;
// constructors and setters etc.
}
//ThingReturner.java
public class ThingReturner {
private LinkedList<Thing> mQueue = new LinkedList<>();
public void putThing(int x, int y, int z, int[][] board) {
mQueue.add(new Thing(x, y, z, board));
}
public Thing[] getThings() {
Thing[] things = new Thing[mQueue.size()];
while (!mQueue.isEmpty()) {
mQueue.pop();
}
return things;
}
}
In my MATLAB code, I have:
javaaddpath '../bin/';
obj = javaObjectEDT('ThingReturner');
obj.putThing(4,6,0,[[1,1,1],[1,0,0],[1,1,1]]);
obj.putThing(2,2,1,[[1,0,1],[1,1,1],[1,0,1]]);
>> obj.getThings()
ans =
Thing[]:
[]
[]
Calling isjava(ans(1))
returns 0 (isjava(ans)
returns 1 though). So how do I properly use the result of getThings()
so I can use ans(1).getX()
etc.?