Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
    Bookmark Topic Watch Topic
  • New Topic

Dig into Generics Doubt

 
Guru dhaasan
Ranch Hand
Posts: 126
Java Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not start a new topic. Continue here where you started.
 
    Bookmark Topic Watch Topic
  • New Topic