JavaAccess

0th

Percentile

Field/method operator for Java objects

The $ operator for jobjRef Java object references provides convenience access to object attributes and calling Java methods.

Keywords
interface
Usage
# S3 method for jobjRef
.DollarNames   (x, pattern = "" )
	# S3 method for jarrayRef
.DollarNames (x, pattern = "" )
	# S3 method for jrectRef
.DollarNames  (x, pattern = "" )
	# S3 method for jclassName
.DollarNames(x, pattern = "" )
Arguments
x

object to complete

pattern

pattern

Details

rJava provies two levels of API: low-level JNI-API in the form of .jcall function and high-level reflection API based on the $ operator. The former is very fast, but inflexible. The latter is a convenient way to use Java-like programming at the cost of performance. The reflection API is build around the $ operator on jobjRef-class objects that allows to access Java attributes and call object methods.

$ returns either the value of the attribute or calls a method, depending on which name matches first.

$<- assigns a value to the corresponding Java attribute.

names and .DollarNames returns all fields and methods associated with the object. Method names are followed by ( or () depending on arity. This use of names is mainly useful for code completion, it is not intended to be used programmatically.

This is just a convenience API. Internally all calls are mapped into .jcall calls, therefore the calling conventions and returning objects use the same rules. For time-critical Java calls .jcall should be used directly.

Methods

$

signature(x = "jobjRef"): ...

$

signature(x = "jclassName"): ...

$<-

signature(x = "jobjRef"): ...

$<-

signature(x = "jclassName"): ...

names

signature(x = "jobjRef"): ...

names

signature(x = "jarrayRef"): ...

names

signature(x = "jrectRef"): ...

names

signature(x = "jclassName"): ...

See Also

J, .jcall, .jnew, jobjRef-class

Aliases
  • $,jobjRef-method
  • $,jclassName-method
  • $<-,jobjRef-method
  • $<-,jclassName-method
  • names,jobjRef-method
  • names,jclassName-method
  • names,jarrayRef-method
  • names,jrectRef-method
  • .DollarNames.jobjRef
  • .DollarNames.jclassName
  • .DollarNames.jarrayRef
  • .DollarNames.jrectRef
Examples
# NOT RUN {
v <- new(J("java.lang.String"), "Hello World!")
v$length()
v$indexOf("World")
names(v)

# }
# NOT RUN {
J("java.lang.String")$valueOf(10)

Double <- J("java.lang.Double")
# the class pseudo field - instance of Class for the associated class
# similar to java Double.class
Double$class 
# }
# NOT RUN {
# }
Documentation reproduced from package rJava, version 0.9-11, License: GPL-2

Community examples

Looks like there are no examples yet.