This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes generic collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "generic collections" Watch "generic collections" New topic
Author

generic collections

Paula Murphy
Greenhorn

Joined: May 26, 2010
Posts: 2
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?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: generic collections
 
Similar Threads
Generics: warnings
Legal add() invocations to List<? super YourFavClass> ? Where's this on K&B ?
Question on Generics
Discussing errata for K&B, SCJP 6
wildcard operator - one doubt ...