External Interfaces Reference Previous page   Next Page
javaObject

Construct Java object

Syntax

Description

javaObject('class_name',x1,...,xn) invokes the Java constructor for class 'class_name' with the argument list that matches x1,...,xn, to return a new object.

If there is no constructor that matches the class name and argument list passed to javaObject, an error occurs.

Remarks

Using the javaObject function enables you to

The default MATLAB constructor syntax requires that no segment of the input class name be longer than 31 characters. (A name segment, is any portion of the class name before, between, or after a period. For example, there are three segments in class, java.lang.String.) Any class name segment that exceeds 31 characters is truncated by MATLAB. In the rare case where you need to use a class name of this length, you must use javaObject to instantiate the class.

The javaObject function also allows you to specify the Java class for the object being constructed at run-time. In this situation, you call javaObject with a string variable in place of the class name argument.

In the usual case, when the class to instantiate is known at development time, it is more convenient to use the MATLAB constructor syntax. For example, to create a java.lang.String object, you would use

Examples

The following example constructs and returns a Java object of class java.lang.String:

See Also
javaArray, javaMethod, import, methods, fieldnames, isjava


Previous page  javaMethod javarmpath Next page

© 1994-2005 The MathWorks, Inc.