Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > I don't understand Cloneable

Reply
Thread Tools

I don't understand Cloneable

 
 
Tim Tyler
Guest
Posts: n/a
 
      08-22-2003
Chris Uppal <> wrote:
: Dale King wrote:

:> > That's a generic problem with using Java interfaces - if you
:> > implement them the world and his wife gets to use them - which
:> > is not necessarily what the programmer wants.
:>
:> Not strictly true. While all members of the interface are public, the
:> interface itself may not be.

: Agreed, and if that's not a clear indication that the spec is
: misconceived then I don't know what would be.

: IMO the condition *should* be that the members required by an interface
: must be at least as accessible as the interface itself.

That wouldn't help with the Cloneable problem. There
we want the inteface to be public - so anyone can use it.

However we don't want to place the burden of making their clone
method public on all the implementors of Cloneable.

So that seems like a case where the member(s) of the interface
ought to be /less/ accessible than the interface itself.
--
__________
|im |yler http://timtyler.org/
 
Reply With Quote
 
 
 
 
Chris Uppal
Guest
Posts: n/a
 
      08-22-2003
Tim Tyler wrote:

> > IMO the condition *should* be that the members required by an
> > interface must be at least as accessible as the interface itself.

>
> That wouldn't help with the Cloneable problem. There
> we want the inteface to be public - so anyone can use it.


Agreed. I was talking about the Java interfaces in general rather than this
specific case.

> However we don't want to place the burden of making their clone
> method public on all the implementors of Cloneable.


I don't see why not. Few objects *shouldn't* be cloned, so it seems to me that
the facility should be "opt out" not "opt in". E.g. Object.clone() could be
public and throw a CloneNotSupportedException if the class in question
didn't support/allow cloning.

-- chris



 
Reply With Quote
 
 
 
 
Tim Tyler
Guest
Posts: n/a
 
      08-22-2003
Chris Uppal <> wrote:
: Tim Tyler wrote:

:> However we don't want to place the burden of making their clone
:> method public on all the implementors of Cloneable.

: I don't see why not. [...]

That is the reason that was given as to why Java's designers didn't
put the clone method in the Cloneable interface:

``Putting the clone() method in the interface would force public
accessibility to that method, which is not an intended effect
of marking a class as Cloneable.''

I think that is a reasonable point - you might not want
the clone method exposed in your public API - you
might want to restrict who can make copies your objects.
--
__________
|im |yler http://timtyler.org/
 
Reply With Quote
 
Bent C Dalager
Guest
Posts: n/a
 
      08-22-2003
In article <>, Tim Tyler <> wrote:
>
>I think that is a reasonable point - you might not want
>the clone method exposed in your public API - you
>might want to restrict who can make copies your objects.


While that is true, I still feel they could have had a PublicClonable
interface for those that _do_ want to expose cloning. This would make
sense for a large number of classes, and would enable people to make
copies of arbitrary clonable objects without serialization or
reflection hacks.

Cheers
Bent D
--
Bent Dalager - - http://www.pvv.org/~bcd
powered by emacs
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cloning a Cloneable Map Ian Pilcher Java 3 10-06-2005 09:13 PM
Cloneable Roedy Green Java 7 07-16-2005 03:58 PM
Why not cloneable by default? Thomas G. Marshall Java 142 04-11-2005 04:37 PM
Cloneable questions Java 3 02-21-2005 06:07 AM
Creating a type-safe Cloneable with generics? Malcolm Ryan Java 4 02-01-2005 01:24 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57