callJavaMethod: Call a Java method

Description Usage Arguments Details Value See Also Examples

View source: R/j4rFunctions.R

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

1
callJavaMethod(source, methodName, ..., affinity = 1)

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

affinity

a parameter used by the mclapply.j4r function in case of multithreading.

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. Primitive type are converted on the fly, numeric to double, integer to int, logical to boolean and character to String. Factors are also converted to String.

When the source is a java.object instance, this function can be substituted for the $ operator.

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.

See Also

J4R webpage

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
### starting Java
connectToJava(memorySize = 200)

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

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

### adding 5 to the list
myList$add(3)

### shutting down Java
shutdownJava()

J4R documentation built on July 23, 2020, 9:06 a.m.