Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Java

Reply
 
LinkBack Thread Tools Display Modes
Old 05-04-2003, 01:51 PM   #1 (permalink)
SkittlesAreYum
Registered User
 
Join Date: Apr 2003
Posts: 8
SkittlesAreYum is on a distinguished road
How to use deep copies (or something like it)?

Okay, for this situation I *think* I need a deep copy, but I'm not sure.

All variables are Strings. Object-type Person is an object class I defined with variables name, add1, add2, phone, and comments. What I'm trying to do is read those variables from a file, create a new Person object with those parameters, and then add this object to a Vector. The code:

Person guest;

for (......)
{
name = reader.readLine().trim();
add1 = reader.readLine().trim();
add2 = reader.readLine().trim();
phone = reader.readLine().trim();
comments = reader.readLine().trim();
guest = new Person(name, add1, add2, phone, comments);
guestsV.addElement(guest);
}

Some of you may already realize it's not working right. It appears that all "versions" of guest refer to the same memory address, so all I get is the same Person object in each Vector location. How do I get it to treat each object as something totally seperate? Do I need to use a deep copy? If so, how? Thanks for any help!
SkittlesAreYum is offline   Reply With Quote
Old 05-04-2003, 03:16 PM   #2 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
well i only had a brief glance but it seems that you are only creating one guest object, so in reality you've added "x" amount of objects to your vector but you only have a handle to one of them via guest

i don't really see the problem? what trouble are you having?
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 01:29 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting