Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #11392

Re: cloning

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail
From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: cloning
Date Mon, 16 Jan 2012 14:03:33 -0800
Organization albasani.net
Lines 54
Message-ID <jf26rl$20s$1@news.albasani.net> (permalink)
References <36a0318f-278e-4f92-8a50-b804b3d7c8f7@k28g2000yqn.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.albasani.net lXIvemUfrN5c9ryxmoKX5qK7/eRWD5FpKWlqSI8joM3FYWHHwh5eWp3G4WcsjGDSjEytuEs1FHxIoZeaNbabgMwl1pHJP+UugYglOB/4nrps3r4GzPRPpOCmGO/Wwmm0
NNTP-Posting-Date Mon, 16 Jan 2012 22:03:34 +0000 (UTC)
Injection-Info news.albasani.net; logging-data="BeDDiPZOvsQwdu9GJnFq9hQgqWWoIZ+xE+nicMfKrM2mCNZcNx+u3cskcx7daW5Ww34rmCodde2phWDjT6OOg6wPRQnXsQGwqGTm8GYPJT/ltGV3vLaTFrVEVjagcO/P"; mail-complaints-to="abuse@albasani.net"
User-Agent Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111109 Thunderbird/3.1.16
In-Reply-To <36a0318f-278e-4f92-8a50-b804b3d7c8f7@k28g2000yqn.googlegroups.com>
Cancel-Lock sha1:93Rzt1n5xp5kDqC0vMxHRNO/FVQ=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11392

Show key headers only | View raw


On 01/16/2012 10:27 AM, albert kao wrote:
> I want to clone the following class so is the following code ok?
> public class TestImpl implements Serializable {

'private static final long serialVersionUID'?

Have you studied up on 'Serializable'?  It's a dangerous tool in the hands of 
the sorcerer's apprentice.
<http://java.sun.com/docs/books/effective/>
Chapter 11, "Serialization"

Yes, he gives it an entire chapter.

>      private int id = 0;

You don't need to initialize 'id' to zero twice.

What's that?  Well, zero is already the default value.  Then you assign zero 
to the variable in a second, explicit initialization.  That's twice.

Having said that, there are sometimes reasons for an explicit initialization 
of a default value, and it's required for 'final' variables.

>      private java.sql.Timestamp createDateTime;

import directives, anyone?

>      private java.sql.Date expiryDate;

I agree that you don't want an import for 'java.sql.Date'.

>      private java.math.BigDecimal amount;

Good choice of type.

>      private java.sql.Timestamp deleteTimestamp;
>
>      // other methods
>      // ...

Really good variable names, by the way.

>      @Override
>      public Object clone() throws CloneNotSupportedException {
>          return (TestImpl)super.clone();
>      }
> }

I suggest that either you eliminate the cast or have a covariant return type.

-- 
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

cloning albert kao <albertkao3@gmail.com> - 2012-01-16 10:27 -0800
  Re: cloning Arne Vajhøj <arne@vajhoej.dk> - 2012-01-16 15:29 -0500
    Re: cloning Lew <noone@lewscanon.com> - 2012-01-16 13:47 -0800
      Re: cloning Arne Vajhøj <arne@vajhoej.dk> - 2012-01-16 16:52 -0500
        Re: cloning Lew <noone@lewscanon.com> - 2012-01-16 14:04 -0800
          Re: cloning Arne Vajhøj <arne@vajhoej.dk> - 2012-01-16 17:14 -0500
  Re: cloning Lew <noone@lewscanon.com> - 2012-01-16 14:03 -0800
  Re: cloning Roedy Green <see_website@mindprod.com.invalid> - 2012-01-17 09:55 -0800
    Re: cloning Arne Vajhøj <arne@vajhoej.dk> - 2012-01-17 17:37 -0500

csiph-web