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


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

Re: cloning

From Lew <noone@lewscanon.com>
Newsgroups comp.lang.java.programmer
Subject Re: cloning
Date 2012-01-16 14:03 -0800
Organization albasani.net
Message-ID <jf26rl$20s$1@news.albasani.net> (permalink)
References <36a0318f-278e-4f92-8a50-b804b3d7c8f7@k28g2000yqn.googlegroups.com>

Show all headers | 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