🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #17720

Re: Cloneable problem

#17720
From: Aaron Gaalswyk
Date: Mon, 05 Oct 1998 00:00
53 lines
1493 bytes
>3.        TargetNode newNode = (TargetNode) ((Cloneable)node).clone();


The Cloneable interface does not define any members, so it does not make
sense to ever cast to it.  In the above case, the code is obviously aware
that it is cloning a TargetNode, so you should instead write

// -->
TargetNode node;
...
if (node instanceof Cloneable)
{
try
{
TargetNode newNode = (TargetNode)node.clone();
}
catch (CloneNotSupportedException k)
{}
}
// <--

The interface TargetNode should have a clone method:

// -->
interface TargetNode
{
Object clone() throws CloneNotSupportedException;
...
}
// <--

This ensures that clone() is public.  If you want to ensure that every class
implementing the TargetNode interface supports cloning, then do

// -->
interface TargetNode
extends Cloneable
{
Object clone();
...
}
// <--

Then you would just write

// -->
TargetNode node;
...
TargetNode newNode = (TargetNode)node.clone();
/ <--


Aaron Gaalswyk
Technical Details
Message-ID: <6vb571$gh220@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36187A77.5F48829B@infodata.sema.se>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,f88a865f106561cf
X-Google-Attributes: gidf74b3,public
From: "Aaron Gaalswyk" <gaalswyk@spacestar.net>
Subject: Re: Cloneable problem
Date: 1998/10/05
Message-ID: <6vb571$gh220@forums.borland.com>
X-Deja-AN: 398001813
References: <36187A77.5F48829B@infodata.sema.se>
X-Mimeole: Produced By Microsoft MimeOLE V4.72.3110.3
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.language