ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephane Chauvin <SChau...@cardiff.com>
Subject RE: Implementing the Clonable interface in a task
Date Mon, 12 Aug 2002 17:56:31 GMT

Hi,
The clone method is implemented in the Object class, so you cannot redefine
the return type.
It is not possible to change the signature of an overridden method. To
change the return type,
you need to rename the method, but in this case it will break the Clonable
interface feature.

For me, it makes more sense to throw the CloneNotSupportedException. Only
the clone method
should throw this exception. It's more the caller of this method that should
catch this exception,
and deals with it, like convert it to an BuildException.

Thanks,
Stephane

-----Original Message-----
From: jlcarpenter@household.com [mailto:jlcarpenter@household.com]
Sent: Monday, August 12, 2002 10:33 AM
To: Ant Developers List
Subject: Implementing the Clonable interface in a task



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>

--
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