External Interfaces/API    

Passing Data to a Java Method

When you make a call from MATLAB to Java code, any MATLAB data types you pass in the call are converted to data types native to the Java language. MATLAB performs this conversion on each argument that is passed, except for those arguments that are already Java objects. This section describes the conversion that is performed on specific MATLAB data types and, at the end, also takes a look at how argument types affect calls made to overloaded methods.

If data is to be returned by the method being called, MATLAB receives this data and converts it to the appropriate MATLAB format wherever necessary. This process is covered in the next section entitled Handling Data Returned from a Java Method.

This section addresses the following topics:

Conversion of MATLAB Argument Data

MATLAB data, passed as arguments to Java methods, are converted by MATLAB into data types that best represent the data to the Java language. The table below shows all of the MATLAB base types for passed arguments and the Java base types defined for input arguments. Each row shows a MATLAB type followed by the possible Java argument matches, from left to right in order of closeness of the match. The MATLAB types (except cell arrays) can all be scalar (1-by-1) arrays or matrices. All of the Java types can be scalar values or arrays.

Table 5-2: Conversion of MATLAB Types to Java Types  
MATLAB Argument
Closest Type (7)
Java Input Argument (Scalar or Array)
Least Close Type (1)
double (logical)
boolean
byte
short
int
long
float
double
double
double
float
long
int
short
byte
boolean
single
float
double





char
String
char





uint8
byte
short
int
long
float
double

uint16
short
int
long
float
double


uint32
int
long
float
double



int8
byte
short
int
long
float
double

int16
short
int
long
float
double


int32
int
long
float
double



cell array of strings
array of String






Java object
Object






cell array of object
array of Object






Data type conversion of arguments passed to Java code will be discussed in the following three categories. MATLAB handles each category differently.


  Creating a Copy of a Java Array Passing Built-In Data Types