Results 1 to 2 of 2
Thread: Copy construtor with enums -
- 11-18-2011, 01:00 AM #1
Member
- Join Date
- Sep 2011
- Location
- Washington DC
- Posts
- 51
- Rep Power
- 0
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
-
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
-
Enums taking in enums?
By rizowski in forum New To JavaReplies: 7Last Post: 06-11-2011, 02:40 PM -
trying to learn enums and arrays
By Gerrburge in forum New To JavaReplies: 9Last Post: 02-02-2011, 03:54 PM -
why should we invoke empty construtor
By prabhajan in forum New To JavaReplies: 5Last Post: 01-31-2011, 06:50 AM -
Returning flags from enums
By willemien in forum New To JavaReplies: 5Last Post: 05-26-2010, 08:37 AM -
why we are using enums in Java?
By manish.anchan in forum New To JavaReplies: 7Last Post: 01-08-2010, 05:41 PM
Bookmarks