External Interfaces Previous page   Next Page

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 7-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
N/A
N/A
N/A
N/A
N/A
char
String
char
N/A
N/A
N/A
N/A
N/A
uint8
byte
short
int
long
float
double

uint16
short
int
long
float
double
N/A
N/A
uint32
int
long
float
double

N/A
N/A
int8
byte
short
int
long
float
double
N/A
int16
short
int
long
float
double
N/A
N/A
int32
int
long
float
double
N/A
N/A
N/A
cell array of strings
array of String
N/A
N/A
N/A
N/A
N/A
N/A
Java object
Object
N/A
N/A
N/A
N/A
N/A
N/A
cell array of object
array of Object
N/A
N/A
N/A
N/A
N/A
N/A

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


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

© 1994-2005 The MathWorks, Inc.