ant-dev mailing list archives

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

If a task (a class extending org.apache.tools.ant.Task) 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 {
            o=(Thing4)super.clone();
      } 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
email: jlcarpenter@household.com



--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message