jnew: Create a Java object

jnewR Documentation

Create a Java object

Description

.jnew create a new Java object.

Usage

.jnew(class, ..., check=TRUE, silent=!check, class.loader=NULL)

Arguments

class

fully qualified class name in JNI notation (e.g. "java/lang/String").

...

Any parameters that will be passed to the corresponding constructor. The parameter types are determined automatically and/or taken from the jobjRef object. For details see .jcall. Note that all named parameters are discarded.

check

If set to TRUE then .jcheck is invoked before and after the call to the constructor to clear any pending Java exceptions.

silent

If set to FALSE then .jnew will fail with an error if the object cannot be created, otherwise a null-reference is returned instead. In addition, this flag is also passed to final .jcheck if check above is set to TRUE. Note that the error handling also clears exceptions, so check=FALSE, silent=FALSE is usually not a meaningful combination.

class.loader

optional class loader to force for loading the class. If not set, the rJava class loader is used first. The default Java class loader is always used as a last resort. Set to .rJava.class.loader inside a package if it uses its own class loader (see .jpackage for details).

Value

Returns the reference (jobjRef) to the newly created object or null-reference (see .jnull) if something went wrong.

See Also

.jcall, .jnull

Examples

## Not run: 
f <- .jnew("java/awt/Frame","Hello")
.jcall(f,,"setVisible",TRUE)

## End(Not run)

rJava documentation built on May 29, 2024, 5:26 a.m.

Related to jnew in rJava...