Are you sure that you want to use an arraylist when you are only using the first item? This looks to me more like a linked list which you could code by adding an airport variable like so:
If I'm wrong and you have to use an ArrayList, then if you use a generic ArrayList<Airport>, your calls to .get(0) would work. If you use a non-generic ArrayList, you can still get it to work, but you'd have to do a bunch of casts. [ April 06, 2007: Message edited by: pete stein ]
Thanks for your input but no it's not what I'm after... What you describe is roughly what I've got. And I use arraylists only because an airport can have more than one destination. The get(0) was just a sample in my code.
I do really need to have references to my airports in my arraylist no the actual values. Why? Because imagine this:
This would print out "Buffalo and Buffalo don't have as many destinations".
The scenario I imagined isn't far-fetched at all. Imagine I have some data representing airports, their names, their codes. I'm parsing that data to build Airport objects.
A holds destination B but has no knowledge of the latter's destinations as they are added later on to b. If I used references rather than values, it would work though.
In general how can I force Java to make a copy by reference rather than value? In other words how can I get the address of my object? And how can I create a new object pointing to the same address?
And you could assume as well that by doing a.addDestination(b) it would add a to be too (although this is making the assumption that this is a bidirectional link which in airlines is a fairly safe but unnnecessary assumption)
Thanks a bunch. [ April 07, 2007: Message edited by: David Brossard ]
No matter what they say in Ohio, we're still first in flight!
I'm not sure that I understand you. When you are dealing with classes and objects, you are already dealing with references. Same for arrays and other containers. If it is a hard absolute physicial address of an object that you are after, well you can't get it, at least not in any easy way that I know about (perhaps exceptions exist by doing some gymnastics w/ the JNI). But regardless since you are dealing w/ references there are very few cases where you'll ever need an absolute physical address. Also, I've heard that trying to manipulate absolute addresses can be very dangerous.
Show us code that you'd like to have work but breaks (and how it breaks). Maybe I'll have a better understanding then. [ April 07, 2007: Message edited by: pete stein ]