CONTENTS | PREV | NEXT Java Remote Method Invocation


2.8 Object Methods Overridden by the RemoteObject Class

The default implementations in the Object class for the equals, hashCode, and toString methods are not appropriate for remote objects. Therefore, the java.rmi.server.RemoteObject class provides implementations for these methods that have semantics more appropriate for remote objects. In this way, all objects that need to be available remotely can extend java.rmi.server.RemoteObject (typically indirectly via java.rmi.server.UnicastRemoteObject).


2.8.1 equals and hashCode

In order for a remote object to be used as a key in a hash table, the methods equals and hashCode are overridden by the java.rmi.server.RemoteObject class:


2.8.2 toString

The toString method is defined to return a string which represents the reference of the object. The contents of the string is specific to the reference type. The current implementation for singleton (unicast) objects includes information about the object specific to the transport layer (such as host name and port number) and an object identifier; references to replicated objects would contain more information.


2.8.3 clone

Objects are only cloneable using the Java language's default mechanism if they support the java.lang.Cloneable interface. Remote objects do not implement this interface, but do implement the clone method so that if subclasses need to implement Cloneable the remote classes will function correctly.

Client stubs are declared final and do not implement clone. Cloning a stub is therefore a local operation and cannot be used by clients to create a new remote object.


2.8.4 finalize

Remote object implementations (subclasses of RemoteObject) can use finalize to perform their own cleanup as necessary. For example, finalize can be used to deactivate an object server.



CONTENTS | PREV | NEXT
Copyright © 1997-1998 Sun Microsystems, Inc. All Rights Reserved.