Check out the new USENIX Web site. next up previous
Next: Avoiding type errors Up: Accessors Previous: Using JAVA reflection

Specifying methods

We have used JAVA reflection for the implementation of the Invoke class shown in Figure 5, a general-purpose accessor. The first constructor enables the expression of a single method invocation. The other constructors shown in the figure enable the creation of an accessor reflecting nested method calls; by specifying an explicitly created nested accessor, or by specifying the names of the methods to be invoked. This adduces the two ways for an application to specify a method:

By method object:
The application explicitly deals with reflection, and provides a Method object. As explained in [BW98], JAVA enforces name equivalence of types, and a method object M is therefore bound to a single type T: if a method M for type T is applied to an object m which does not conform to T, null is returned - even if m implements a method of the same name and signature than M. By specifying methods as objects, the application implicitly defines the type of message objects it is interested in.
By method name (and signature):
Specifying the name of a method and its arguments (and implicitly the method's signature) can be interesting to enforce structure equivalence of types, i.e., subscribing to all objects which implement a given method, independently of their type. This implies, for each evaluated message object, a dynamic lookup of the corresponding method object (through java.lang.Class) by the accessor.

In Section 5 we evaluate the two possibilities in terms of efficiency, and show that the knowledge of the type of message objects is important for performance optimizations.


next up previous
Next: Avoiding type errors Up: Accessors Previous: Using JAVA reflection
Patrick Eugster
12/10/2000