Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List<E>.remove(Object? value) should use type E instead of Object? #60378

Closed
drxddy opened this issue Mar 21, 2025 · 2 comments
Closed

List<E>.remove(Object? value) should use type E instead of Object? #60378

drxddy opened this issue Mar 21, 2025 · 2 comments

Comments

@drxddy
Copy link
Contributor

drxddy commented Mar 21, 2025

Since List<E> is a generic, where each list element is an object in it will adhere to type E,

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.

abstract class List<E> {
  /// proposal
  bool remove(E? value);

  /// instead of
  bool remove(Object? value);
}
  • 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?

@drxddy 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 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 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
@FMorschel
Copy link
Contributor

CC @lrhn

@lrhn
Copy link
Member

lrhn commented Mar 22, 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.

Still no plan to change it.

@lrhn lrhn closed this as not planned Won't fix, can't repro, duplicate, stale Mar 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants