Learn R Programming

J4R (version 1.0.7)

callJavaMethod: Call a Java method

Description

This function calls a public method in a particular class of object. If the javaObject parameters or the additional parameters (...) include vectors, the method is called several times and a vector of primitive or a list of java instances can be returned.

Usage

callJavaMethod(source, methodName, ...)

Arguments

source

this should be either a java.list instance or a single java.object instance for non-static methods or a string representing the Java class name in case of static method

methodName

the name of the method

...

the parameters of the method

Value

It depends on the method. It can return a primitive type (or a vector of primitive), a Java instance (or a list of Java instances) or nothing at all.

Details

There is no need to cast a particular parameter to a super class. Actually, the Java server tries to find the method that best matches the types of the parameters

See Also

J4R webpage

Examples

Run this code
# NOT RUN {
### starting Java
connectToJava()

### creating an empty ArrayList object
myList <- createJavaObject("java.util.ArrayList")

### adding 3 to the list
callJavaMethod(myList, "add", 3)

### shutting down Java
shutdownJava()

# }

Run the code above in your browser using DataLab