SJava (version 0.98.0)

jdynamicCompile: Dynamically Compile a Java Class

Description

This uses the dynamic byte-code generator facility in Omegahat to create a new Java class with a given name. By default, the new class extends the RForeignReference class and implements a specifiable collection of Java interfaces. Each method in these interfaces is implemented by calling the corresponding R function in the R reference object.

Usage

jdynamicCompile(interface, newClass, generatorClass="ForeignReferenceClassGenerator", load=TRUE)

Arguments

interface
the (fully qualified) name of one or more Java interface classes that the new class should implement. The methods in these interfaces are implemented as calls to the correspondingly named R function in the R object identified by the RForeignReference's key.
newClass
the name of the new class to be created.
generatorClass
the name of the Java class to which is to be used as the dynamic compiler. This is rarely specified, but allows one to use classes that implement the code differently, e.g. by extending ForeignReferenceClassGenerator.
load
logical value indicating whether the new class should be loaded into the Omegahat list of available classes. If this is FALSE, one usually writes the newly generated class definition to a file.

References

http://www.omegahat.org

Examples

Run this code
 ## Not run: 
#   jdynamicCompile("java.awt.event.ActionListener", "RActionListener")
#   l <- .JNew("RActionListener",
#              foreignReference(list(actionPerformed=function() print("ok"))))
#   button$add(l)
#  ## End(Not run)

## Not run: 
#   def <- jdynamicCompile("java.awt.event.ActionListener",
#                          "RActionListener", load=F)
#   def$write()
#  ## End(Not run)

Run the code above in your browser using DataCamp Workspace