• 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

Generic doubt

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand why I would get a compiler error (incompatible types) when trying to past an ArrayList into a method that excepts a List. An ArrayList is-a List.
I can do this: 'List<String> list = new ArrayList<String>();
So why can't I do it with the method argument?



Thanks,
 
Ranch Hand
Posts: 447
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Jeff Schuler


How can you assign a super class reference to a sub class reference ?

Here ArrayList is-A List


Have you Got it ?


Thanks

Anil Kumar
[ July 02, 2007: Message edited by: anil kumar ]
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is not with the argument. it is with the return type. It expected a List but found ArrayList which is a subclass. You can typecast it.

cheers,
nitin
 
Jeff Schuler
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by anil kumar:
Hi

Jeff Schuler


How can you assign a super class reference to a sub class reference ?

Here ArrayList is-A List


Have you Got it ?


Thanks

Anil Kumar

[ July 02, 2007: Message edited by: anil kumar ]



Thanks, I got it. I have to start reading the questions more carefully.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic