8000 Type-safe `containsKey` `get`, et al · Issue #28 · goldmansachs/gs-collections · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Type-safe containsKey get, et al #28
Open
@io7m

Description

@io7m

Hello.

The standard JDK Map<K, V> interfaces contain methods such as containsKey that take an Object instead of a K, throwing away type-safety. I believe this is now considered to be a serious historical mistake and dangerous to the point that some IDEs have added specific checks to warn users when they might be using keys that aren't subtypes of K. I'm wondering if there are any plans to add additional type-safe replacement methods to the MutableMap and ImmutableMap interfaces specified in the GS API? Something along the lines of:

Optional<V> retrieve(K k)
boolean hasKey(K k);

... or:

@Nullable V retrieve(K k)

... if a dependency on Java 8 isn't allowed.

As far as I can tell, the implementations would be trivial and non-intrusive, and would obviously just be defined in terms of the existing unsafe methods.

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

      0