my dog learned polymorphism*
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply locked New topic
Author

Dig into Generics Doubt

Guru dhaasan
Ranch Hand

Joined: Sep 13, 2006
Posts: 126

Hi

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();
bar.doInsert(mylist);
}
}

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,
Guru


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: http://aspose.com/file-tools
 
subject: Dig into Generics Doubt