This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what is wrong with this Arraylist expression

 
Adam Zedan
Ranch Hand
Posts: 124
C++ Fedora Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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 ??

 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
C++ Fedora Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code is



I am using eclipse SE ..
 
Piyush Joshi
Ranch Hand
Posts: 207
Eclipse IDE Firefox Browser jQuery
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
C++ Fedora Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Worked...thanks.. Removed the otehr import statement.. Thanks for clearing that up
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic