Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

new clone feature

Thread view: 
Roedy Green - 05 Feb 2006 01:46 GMT
There is supposed to be a way you can avoid the cast from clone.

What is the feature called and how do you use it.
There is apparently more to it that just saying

public Footprint clone()
       
instead of

public Object clone()
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

Stefan Ram - 05 Feb 2006 01:59 GMT
>What is the feature called and how do you use it.
>There is apparently more to it that just saying
> public Footprint clone()
>instead of
>public Object clone()

     »Note that this definition supports covariant returns -
     that is, the specialization of the return type to a
     subtype (but only for reference types).«

   Java Language Specification, Third Edition,
   8.4.5 Method Return Type
Paul Tomblin - 05 Feb 2006 03:14 GMT
In a previous article, Roedy Green <my_email_is_posted_on_my_website@munged.invalid> said:
> public Footprint clone()

Maybe it's because I come from a C++ background, but I've always preferred
to make a copy constructor rather that rely on clone().  So I would write
   Footprint myClone = new Footprint(myOldFootprint);
rather than
   Footprint myClone = (Footprint)myOldFootprint.clone();

Signature

Paul Tomblin <ptomblin@xcski.com> http://xcski.com/blogs/pt/
"If Bill Gates had a dime for every time a Windows box crashed...
.... Oh, wait a minute, he already does."

Paul Tomblin - 05 Feb 2006 14:08 GMT
In a previous article, ptomblin+netnews@xcski.com (Paul Tomblin) said:
>In a previous article, Roedy Green
><my_email_is_posted_on_my_website@munged.invalid> said:
[quoted text clipped - 5 lines]
>rather than
>    Footprint myClone = (Footprint)myOldFootprint.clone();

I should mention that I'm aware of the usefulness of the clone situation
where the item you're cloning might be one of several subclasses of the
"Footprint" and you want the new one to be the right one.

Signature

Paul Tomblin <ptomblin@xcski.com> http://xcski.com/blogs/pt/
Usenet should require licenses; licenses that can be revoked.
             -- Abigail



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.