.jcall
calls a Java method with the supplied arguments..jcall(obj, returnSig = "V", method, ..., evalArray = TRUE,
evalString = TRUE, check = TRUE, interface = "RcallMethod")
int[]
etc.). For convenience additional type
"S"
is supported and expanded to
"Ljava/lang/String;"
, re-mapping "T"
to represent tjobjRef
object. All named parameters are discarded.TRUE
) or passed back as Java object reference
(FALSE
).TRUE
then checks for exceptions are
performed before and after the call using
.jcheck(silent=FALSE)
. This is usually the desired
behavior, because all calls fail until an "RcallMethod"
"RcallSyncMeth
.jcall
requires exact match of argument and return types. For
higher efficiency .jcall
doens't perform any lookup in the
reflection tables. This means that passing subclasses of the classes
present in the method definition requires explicit casting using
.jcast
. Passing null
arguments also needs a
proper class specification with .jnull
. Java types long
and float
have no corresponding types in
R and therefore any such parameters must be flagged as such using
.jfloat
and .jlong
functions respectively.
Java also distinguishes scalar and array types whereas R doesn't have
the concept of a scalar. In R a scalar is basically a vector (called
array in Java-speak) of the length 1. Therefore passing vectors of the
length 1 is ambiguous. .jcall
assumes that any vector of the
length 1 that corresponds to a native Java type is a scalar. All other
vectors are passed as arrays. Therefore it is important to use
.jarray
if an arbitrary vector (including those of the
length 1) is to be passed as an array parameter.
.jnew
, .jcast
, .jnull
,
.jarray
.jcall("java/lang/System","S","getProperty","os.name")
f <- .jnew("java/awt/Frame","Hello")
.jcall(f,,"setVisible",TRUE)
Run the code above in your browser using DataLab