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
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.
The text was updated successfully, but these errors were encountered:
We currently don't have overloads of containsKey and get but could add them. We have a similar overload of the remove method MutableMapIterable.removeKey(K k): V.
We would probably use the name getKey for the overload of get. We would need to come up with a name for the overload of containsKey, or use your suggestion of hasKey.
I might suggest getValue for the get override, because you're obviously retrieving a value and not a key as getKey would suggest. I've no real preference for any of the names, just getting back type-safety will be enough.
Hello.
The standard JDK
Map<K, V>
interfaces contain methods such ascontainsKey
that take anObject
instead of aK
, 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 ofK
. I'm wondering if there are any plans to add additional type-safe replacement methods to theMutableMap
andImmutableMap
interfaces specified in the GS API? Something along the lines of:... 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.
The text was updated successfully, but these errors were encountered: