File: accessOp.Rd

package info (click to toggle)
rjava 1.0-14-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,188 kB
  • sloc: java: 13,223; ansic: 5,503; sh: 3,776; xml: 325; makefile: 250; perl: 33
file content (83 lines) | stat: -rw-r--r-- 3,166 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
\name{JavaAccess}
\alias{$,jobjRef-method}
\alias{$,jclassName-method}
\alias{$<-,jobjRef-method}
\alias{$<-,jclassName-method}
\alias{names,jobjRef-method}
\alias{names,jclassName-method}
\alias{names,jarrayRef-method}
\alias{names,jrectRef-method}
\alias{.DollarNames.jobjRef}
\alias{.DollarNames.jclassName}
\alias{.DollarNames.jarrayRef}
\alias{.DollarNames.jrectRef}

\title{
  Field/method operator for Java objects
}
\description{
  The \code{$} operator for \code{jobjRef} Java object references provides convenience access to object attributes and calling Java methods.
}
\usage{
	\S3method{.DollarNames}{jobjRef}   (x, pattern = "" )
	\S3method{.DollarNames}{jarrayRef} (x, pattern = "" )
	\S3method{.DollarNames}{jrectRef}  (x, pattern = "" )
	\S3method{.DollarNames}{jclassName}(x, pattern = "" )
}
\arguments{
	\item{x}{object to complete}
	\item{pattern}{pattern}
}
\section{Methods}{
  \describe{
    \item{\code{$}}{\code{signature(x = "jobjRef")}: ... }
    \item{\code{$}}{\code{signature(x = "jclassName")}: ... }
    \item{\code{$<-}}{\code{signature(x = "jobjRef")}: ... }
    \item{\code{$<-}}{\code{signature(x = "jclassName")}: ... }
    \item{\code{names}}{\code{signature(x = "jobjRef")}: ... }
    \item{\code{names}}{\code{signature(x = "jarrayRef")}: ... }
    \item{\code{names}}{\code{signature(x = "jrectRef")}: ... }
    \item{\code{names}}{\code{signature(x = "jclassName")}: ... }
	 }
}
\details{
  rJava provides two levels of API: low-level JNI-API in the form of \code{\link{.jcall}} function and high-level reflection API based on the \code{$} 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 \code{$} operator on \code{\link{jobjRef-class}} objects that allows to access Java attributes and call object methods.

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

 \code{$<-} assigns a value to the corresponding Java attribute.

 \code{names} and \code{.DollarNames} returns all fields and methods associated with the object.
 Method names are followed by \code{(} or \code{()} 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 \code{\link{.jcall}} calls, therefore the calling conventions and returning objects use the same rules. For time-critical Java calls \code{\link{.jcall}} should be used directly.
}
\seealso{
  \code{\link{J}}, \code{\link{.jcall}}, \code{\link{.jnew}}, \code{\link{jobjRef-class}}
}
\examples{
\dontshow{.jinit()}

v <- new(J("java.lang.String"), "Hello World!")
v$length()
v$indexOf("World")
names(v)

\dontshow{
stopifnot( v$length() == 12L )
stopifnot( v$indexOf("World") == 6L )
}

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
\dontshow{
	stopifnot( Double$class$getName() == "java.lang.Double" )
}

}
\keyword{interface}