Results 1 to 2 of 2
  1. #1
    danthegreat is offline Member
    Join Date
    Sep 2011
    Location
    Washington DC
    Posts
    51
    Rep Power
    0

    Default Copy construtor with enums -

    What would be considered a shallow copy?

    Is this acceptable:

    Java Code:
    //still shallow copy?	//copy constructor for client needs
    	public Card(Card toCopy)
    	{
    		SUIT copy_s=toCopy.theSuit;
    		RANK copy_r=toCopy.theRank;
    		this.theSuit=copy_s;
    		this.theRank=copy_r;
    
    
    }

    SUIT represents values: CLUBS, DIAMONDS, HEARTS, SPADES
    RANK represents values: TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE

    how would I be able to make this shall I say "unshallow"?

    Thanks

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default Re: Copy construtor with enums -

    I believe that there is no need for a "deep" copy constructor here since all fields are either enums or primitives, so you're good. I'd simplify it though:

    Java Code:
        public Card(Card toCopy) {
            theSuit = toCopy.theSuit;
            theRank = toCopy.theRank;
        }

Similar Threads

  1. Enums taking in enums?
    By rizowski in forum New To Java
    Replies: 7
    Last Post: 06-11-2011, 02:40 PM
  2. trying to learn enums and arrays
    By Gerrburge in forum New To Java
    Replies: 9
    Last Post: 02-02-2011, 03:54 PM
  3. why should we invoke empty construtor
    By prabhajan in forum New To Java
    Replies: 5
    Last Post: 01-31-2011, 06:50 AM
  4. Returning flags from enums
    By willemien in forum New To Java
    Replies: 5
    Last Post: 05-26-2010, 08:37 AM
  5. why we are using enums in Java?
    By manish.anchan in forum New To Java
    Replies: 7
    Last Post: 01-08-2010, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •