ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Implementing the Clonable interface in a task
Date Mon, 12 Aug 2002 17:32:52 GMT

If a task (a class extending implements the
Clonable interface how should it deal with subclasses whose clone method
throw a CloneNotSupportedException?

The following code snipt from Thinking in Java page 1032 shows a try catch
block around the call to super.clone().

public Object clone() {
      Thing4 o = null;
      try {
      } catch (CloneNotSupportedException e) {
            System.err.println("Thing4 can't clone");
      //bla bla bla


Printing to System.err doesn't seem to be the right thing.  Should I throw
a BuildException?

I have been away from java for a year or so.  Can anyone remind me why the
clone method's return type is object instead of the type of object
being cloned?  Isn't it a bit sloppy to require casting the cloned object?

Someone out there may be wondering why I am looking to clone an Ant task.
I am creating two tasks that use the CVS task by composition.  This same
approach is taken by the CvsTagDiff task.  The two classes I am writting
also have some shared functionality that should be moved off into a utility
class.  The complication is that the utility class must have a configured
CVS object to do its job.  The simplest way to configure the CVS instance
used by the utility is to simply clone the CVS instance within the client
class and pass it to the utility class's constructor or as an argument to
any static method.

James Lee Carpenter
Software Engineer
Household Technical Services
6602 Convoy Court
San Diego, CA 92111

ph: 858-609-2461

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message