Download 3 - McMaster Physics and Astronomy

Transcript
Passing Data to a Java Method
has dimension 1, and a 1-by-1 array has dimension 0. In Java, dimension is
determined solely by the number of nested arrays. For example, double[][]
has dimension 2, and double has dimension 0.
If the Java array’s number of dimensions exactly matches the MATLAB
array’s number of dimensions n, the conversion results in a Java array with n
dimensions. If the Java array has fewer than n dimensions, the conversion
drops singleton dimensions, starting with the first one, until the number of
remaining dimensions matches the number of dimensions in the Java array.
Empty Matrices and Nulls
The empty matrix is compatible with any method argument for which NULL is
a legal value in Java. The empty string ('') in MATLAB translates into an
empty (not NULL) String object in Java.
Passing Data to Overloaded Methods
When you invoke an overloaded method on a Java object, MATLAB
determines which method to invoke by comparing the arguments your call
passes to the arguments defined for the methods. Note that in this discussion,
the term method includes constructors. When it determines the method to
call, MATLAB converts the calling arguments to Java method types according
to Java conversion rules, except for conversions involving objects or cell
arrays. See “Passing Objects in an Array” on page 7-59.
How MATLAB Determines the Method to Call
When your MATLAB function calls a Java method, MATLAB
1 Checks to make sure that the object (or class, for a static method) has a
method by that name.
2 Determines whether the invocation passes the same number of arguments
of at least one method with that name.
3 Makes sure that each passed argument can be converted to the Java type
defined for the method.
If all of the preceding conditions are satisfied, MATLAB calls the method.
7-61