callJavaMethod | R Documentation |
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.
callJavaMethod(source, methodName, ..., affinity = 1)
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. |
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.
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.
### 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
shutdownClient()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.