Forums Register Login

Dig into Generics Doubt

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Please do not start a new topic. Continue here where you started.
If you're gonna buy things, buy this thing and I get a fat kickback:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


Reply locked
This thread has been viewed 632 times.
Similar Threads
Generics
Generics
wildcard type parameter
compareTo()
generics / adding to wildcard Collection
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:51:39.