This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

objects

 
Gregor Pavlic
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello...

I'm new here and I need help...
If I create objects like this...



Can I access the data for individual object, or can't I??

Thanks...
 
Campbell Ritchie
Sheriff
Posts: 48402
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.


Welcome to the Ranch
What you are doing is creating each object inside the loop, and not keeping a variable (at least not in the code shown) which points to it outside the loop. When you get to the end of the loop, player points to the last‑created object.
Maybe you meant to keep the Player objects in a List or an array. Maybe the addPlayerInfo method does keep a copy of all their references.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic