• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

generic collections

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am unsure about generics and i have a few questions:

What are the rules regarding passing a generic collection as an argument to a method where the method parameter is
1. a non generic collection?
2. a generic collection?

What are the rules for passing a non generic collection as an argument to a method where the method parameter is a generic collection?

If you override a method, with a generic parameter, does the overriding method have to have a parameter with the same generic?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch


Paula Murphy wrote:
What are the rules regarding passing a generic collection as an argument to a method where the method parameter is
1. a non generic collection?
2. a generic collection?



you can pass. you will get *warning* if the parameter or argument is not a generic

Paula Murphy wrote:What are the rules for passing a non generic collection as an argument to a method where the method parameter is a generic collection?


you can pass[vice-versa is true also] . there is an only one rule is that *always use generic*

Paula Murphy wrote:If you override a method, with a generic parameter, does the overriding method have to have a parameter with the same generic?



say super class has a method which has generic parameter , but overriding method in subclass can have non-generic parameter[but it cant have different generic type] . but vice-versa is not true.

the thumb rule is that dont mix non-generic collection into generic collection

hth
 
Please enjoy this holographic presentation of our apocalyptic dilemma right after this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic