File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Dig into Generics Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic

Dig into Generics Doubt

Guru dhaasan
Ranch Hand

Joined: Sep 13, 2006
Posts: 126


supposing I have the following code:

public class TestwildCards{
public static void main(String arg[]){
List<Integer> mylist=new ArrayList<Integer>();
Bar bar=new Bar();

class Bar{
void doInsert(List<Object> list){
list.add(new Dog());

Will this compile or not ???

Sincd Polymorphism applies to base type only and not to the parameterized type. Here neither the base type nor the parameterized type changes

Will the Dog object be added into the Integer list???

Also what is the difference does it make between List<?> and List<object> ???


Thanks, Shiv
SCJP, OCE - JSP & Servlets Developer
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Please do not start a new topic. Continue here where you started.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
I agree. Here's the link:
subject: Dig into Generics Doubt
It's not a secret anymore!