This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 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
 
Similar Threads
compareTo()
Generics doubt K&B
Generics
wildcard type parameter
Generics