When passing cell arrays of Java objects to a Java method using auto conversion, I expect the created Java array to have the type of the contained arrays, such as java.util.Hashtable in this example. However, the array is created as an array of type java.lang.Object.
For example, I have the following java class; the hello method of this class accepts a single input which is an array of type Hashtable.
public class MatlabJavaBug { public static void hello(java.util.Hashtable hash[]) { System.out.println( "Hello, World!"); } }
I compile this code and add it to the MATLAB java path as follows:
!javac MatlabJavaBug.javajavaaddpath(pwd)
I then create a Hashtable variable which is the type expected by the above function.
h1 = java.util.Hashtable;h1.put('a',3);
If I use the javaArray function to create an array of hash tables, the function call is successful.
jHarray = javaArray('java.util.Hashtable',1);jHarray(1) = h1; MatlabJavaBug.hello(jHarray)
However, if I create a cell array of hash tables, the command fails
carray = {h1}MatlabJavaBug.hello(carray)
with the following error message:
??? No method 'hello' with matching signature found for class 'MatlabJavaBug'.
The documentation states that the cell array should be converted to a java array of the appropriate type.
Best Answer