| Author |
Passing ArrayList
|
R Jarman
Greenhorn
Joined: Feb 08, 2005
Posts: 27
|
|
I have a class with a private variable privateArrayList<Bid>bids = new ArrayList<Bid>(); I'm setting this variable in the constructor for the class, so the constructor looks like this. public Pruning ( ArrayList _bids) { bids.addAll ( _bids ); } I don't think I'm doing something right. How do I tell the constructor the type of the argument. I tried public Pruning ( ArrayList<Bid> _bids) like I did in the variable declaration but it won't compile. What am I missing?
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
I tried public Pruning ( ArrayList<Bid> _bids) like I did in the variable declaration but it won't compile. What am I missing?
That looks okay. What type of error message did the compiler give?
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Robert Hill
Ranch Hand
Joined: Feb 24, 2006
Posts: 94
|
posted

0
|
How are you invoking the constructor? ie Pruning p = new Pruning(bids) Why do you instantiating an ArrayList as a private member and then passing another one in the constructor. Is that what you want? This might be what you want: private ArrayList<Bid> bids; public Pruning ( ArrayList<Bid> _bids) { bids = _bids; } addAll() appends the passed list to the private one, but the private list has no elements yet.
|
 |
 |
|
|
subject: Passing ArrayList
|
|
|