• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Mike London

issue with object overwriting itself when I need it to create separat instances(nevermind I got it)

Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the code:

It first creates a new DeviceChannel Object, which is the one I need multiple instances of. It then passes a url value to a method in ordeer to get xml from a web service and populate the Device class with it. I then create a list called dc that holds DeviceChannel Objects. Then i do operations to fill the DeviceChannel class with values, add it to eh dc List, and then add that List to another List in another class.

At the end it prints out the name of the deviceName and the representation of the Object holding that deviceName.

The deviceName prints out two different deviceNames like it is suposed to, but for some reason the print out of the DeviceChannels Object representation is always the same Object, not two separate Objects as intended.

ANy idea where I need to change this?

Here is the full code if you want to see it, it has the above for loop nested in another for loop. The first one sets the projectName in a class, and the second for loop I am having issues with is intended to set a List that is in that same class, so I will end up with an Object that has a projectName, and a List of Objects. Everything works except the list of DeviceChannel Objects, because the second iteration is overwriting the first leaving me with two of the same DeviceChannel Objects in my List.,:

    Bookmark Topic Watch Topic
  • New Topic