Products & Services Industries Academia Support User Community Company

Learn more about MATLAB   

javaObject - Construct Sun Java object

Syntax

javaObject('ClassName',x1,...,xn)

Description

javaObject('ClassName',x1,...,xn) calls the Java constructor for class ClassName 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

Use the javaObject function 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.

class  = 'java.lang.String';
text = 'hello';
strObj = javaObject(class, text);

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, type:

strObj = java.lang.String('hello');

Examples

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

strObj = javaObject('java.lang.String','hello')

See Also

javaArray, javaMethod, import, methods, fieldnames, isjava, javaObjectEDT

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS