| Author |
what is wrong with this Arraylist expression
|
Adam Zedan
Ranch Hand
Joined: Jun 10, 2011
Posts: 124
|
|
The above code generates an error .. why ??
i know that Collection is an interface and List is also an interface which inherits from Collection and Arraylist is an implimentation of List then why the error??
even the site http://www.javamex.com/tutorials/collections/using_1.shtml
is using it this way ... am i missing anything ??
|
Don’t look where you fall, but where you slipped
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3793
|
|
Is that exactly how the code appears? Because an import statement needs to be at the beginning of the file, and the other line needs to be within a class.
Otherwise, it would be helpful if you gave the error message.
|
 |
Adam Zedan
Ranch Hand
Joined: Jun 10, 2011
Posts: 124
|
|
The code is
I am using eclipse SE ..
|
 |
Piyush Joshi
Ranch Hand
Joined: Jun 10, 2011
Posts: 207
|
|
Adam Zedan wrote:The code is
I am using eclipse SE ..
Hi, dont use java.awt.List this List is different from the List in Collections framework.
You have already imported complete java.util package which contains java.util.List and java.util.ArrayList
|
Piyush
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3793
|
|
Piyush is right. It's trying to use the wrong List.
If you do need java.awt.List in that file, then you can get round it by using the fully qualified name:
|
 |
Adam Zedan
Ranch Hand
Joined: Jun 10, 2011
Posts: 124
|
|
Worked...thanks.. Removed the otehr import statement.. Thanks for clearing that up
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32675
|
|
|
Beware of imports in IDEs. If you write L-i-s-ctrl-space in Eclipse®, it will expand it to anything beginning with Lis, including java.awt.List and java.util.List. It displays the options in alphabetical order, so awt comes before util, and you can very easily pick the wrong List.
|
 |
 |
|
|
subject: what is wrong with this Arraylist expression
|
|
|