External Interfaces/API | ![]() ![]() |
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');
Using the javaMethod Function on Static Methods
The javaMethod
function was introduced in section Using the javaMethod Function on Non-Static Methods. You can also use this function to call static methods.
The following syntax invokes the static method, method_name
, in class, class_name
, with the argument list that matches x1,...,xn
. This returns the value X
.
X = javaMethod('method_name','class_name',x1,...,xn);
For example, to call the static isNaN
method of the java.lang.Double
class on a double value of 2.2, you use
javaMethod('isNaN','java.lang.Double',2.2);
Using the javaMethod
function to call static methods enables you to:
For further information, see Using the javaMethod Function on Non-Static Methods.
![]() | Invoking Methods on Java Objects | Obtaining Information About Methods | ![]() |