• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what is wrong with this Arraylist expression

 
Ranch Hand
Posts: 124
C++ Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ??

 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code is



I am using eclipse SE ..
 
Ranch Hand
Posts: 207
jQuery Eclipse IDE Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Worked...thanks.. Removed the otehr import statement.. Thanks for clearing that up
 
Marshal
Posts: 79415
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic