• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Run-time reference naming

 
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic