This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes what is wrong with this Arraylist expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "what is wrong with this Arraylist expression" Watch "what is wrong with this Arraylist expression" New topic
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: 4344
    
    8

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: 4344
    
    8

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: 38107
    
  22
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: what is wrong with this Arraylist expression
 
Similar Threads
Returning ArrayList "type incompatible" error
Why use List intefrace to create a ArrayList and not ArrayList class?
from mock test
Map interface - keySet function
This Generics work (At least in my compiler)