Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Collection LinkedList Function Argument Types [duplicate]

Possible Duplicate:
Why aren't Java Collections remove methods generic?

I noticed that few of the LinkedList operations take Generic parameter type E, while a few take 'Object' as the parameter. For ex,

add(E e) 
remove(Object o) 

Is there a specific reason to do that? Why not make 'remove' take a generic type E. (I know it doesn't matter after type erasure, but just wondering).

like image 336
vikky.rk Avatar asked Nov 13 '22 01:11

vikky.rk


1 Answers

This is because removal operation checks for equality using equals() method and equals() method takes in an Object as parameter not generic .

like image 78
amicngh Avatar answered Nov 30 '22 22:11

amicngh