This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Run-time reference naming  RSS feed

 
Barkat Mardhani
Ranch Hand
Posts: 787
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class obj1 = new Class()
In above statement obj1 is object reference. If number of such object references needed at run-time is not known at compile time, how would you come up with next object reference e.g. obj2? In other words, can you put a function call in place of obj1 that return new name. I know you can use arrays but they are also fixed length. I have little knowledge that there are some container that adjust their size at run-type. Any other idea?
Thanks
Barkat Mardhani
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Barkat
Check out the Vector and the ArrayList classes. They are both resizable collections. so you could generate a number of object references at run time with out knowing in advance how many you were going to need. Of course, in many cases, you can do this with an array too, you just dont declare the array until you know how big it is going to be.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!