Safe copying

Hello all.

I'm trying to create an application to produce arithmetic functions that use a generic Guess interface, but I'm not sure how to ensure that I have a "clean" Guess object for my calculations. A simple object reference could originate from a source I don't trust and therefore be attacked during the calculation. I'm therefore trying to work out if it's possible to make a defensive copy of an Interface class whose implementation I don't know.

I've settled on the idea of an abstract class that implements the Cloneable interface as well as Guess, with a 'protected final' clone() method that simply calls super.clone() (ie, Object's).

Is this sufficient, or will it simply return a binary copy of my abstract class whatever subclass it's called from because it's declared final? There seems to be very little info on the mechanics of the Cloneable interface and exactly how this works.

Alternatively, has anyone else run into this problem and, if so, how did you solve it?

Thanks in advance

Winston

[1064 byte] By [YoungWinstona] at [2007-11-26 18:56:12]
# 1
NO. It is not enough. If You are interested in state of the object You have You need to populate colone() with code copying the state.And if You need to pass Your objects to untrusted code it is good idea to implement read only wrappers.
_Dima_a at 2007-7-9 20:35:00 > top of Java-index,Core,Core APIs...