Skip to content

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

Closed as not planned
@drxddy

Description

@drxddy

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions