You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Observed that indexOf(E element, [int start = 0]) is generic and expects the same type E element as in List<E>
Also noticed that contains(Object? value) also uses Object? param
Why is it better to use Object? instead of E?
The text was updated successfully, but these errors were encountered:
drxddy
changed the title
List.remove method should use Generic type instead o Object?
List.remove method should use Generic type instead of Object?
Mar 21, 2025
drxddy
changed the title
List.remove method should use Generic type instead of Object?
List<E>.remove(Object? value) should use Generic type instead of Object?
Mar 21, 2025
drxddy
changed the title
List<E>.remove(Object? value) should use Generic type instead of Object?
List<E>.remove(Object? value) should use type E instead of Object?
Mar 21, 2025
There are lots of prior issues for this.
The design is made the way it is to allow an up-cast collection to work.
Changing it now, even if we wanted to, would be breaking, and unlikely to be worth that breakage.
Since
List<E>
is a generic, where each list element is an object in it will adhere to typeE
,Proposing a generic remove method to make the api more type safe, open to hear about why it was kept this way, and why, if it's better.
indexOf(E element, [int start = 0])
is generic and expects the same typeE
element as inList<E>
contains(Object? value)
also usesObject?
paramWhy is it better to use
Object?
instead ofE?
The text was updated successfully, but these errors were encountered: