User`s manual
Invoking Methods on Java Objects
5-21
With javaMethod, you can also specify the method to be invoked at run-time.
In this situation, your code calls
javaMethod with a string variable in place of
the
method name argument. When you use javaMethod to invoke a static
method, you can also use a string variable in place of the class name argument.
Note Typically, you will not need to use javaMethod. The default MATLAB
syntax for invoking a Java method is somewhat simpler and is preferable for
most applications. Use
javaMethod primarily for the two cases described
above.
Invoking Static Methods on Java Classes
To invoke a static method on a Java class, use the Java invocation syntax
class.method(arg1,...,argn)
For example, call the isNaN static method on the java.lang.Double class.
java.lang.Double.isNaN(2.2)
Alternatively, you can apply static method names to instances of a class. In this
example, the
isNaN static method is referenced in relation to the dblObject
instance of the
java.lang.Double class.
dblObject = java.lang.Double(2.2);
dblObject.isNaN
ans =
0
Several of the programming examples in this chapter contain examples of
static method invocation. For example, the code for Communicating Through a
Serial Port contains a call to static method
getPortIdentifier on Java class
javax.comm.CommPortIdentifier.
commPort =
javax.comm.CommPortIdentifier.getPortIdentifier('COM1');