yangxu998 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Change signature to `V Table.get(R, C)` #658

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
The `Table` interface provides a `get` method which accepts two arguments of 
type `Object`. This is similar to the JDK's `Map` interface due to reasons I 
can only speculate about (namely related to the behaviour of `equals` 
implementations). In both cases the `Object` type for arguments is only allowed 
to containment checks and value retrieval, not for mutator methods.

However, a difference between `Map` and `Table` is that the latter accepts two 
arguments instead of one. Without type information, AFAIK neither the compiler 
nor IDE completion can assist in checking whether or not the values (a) are 
suitable at all and (b) are given in the right order. Mixing up the row and 
column key arguments can yield unexpected, possibly hard-to-track results.

So, though I sense some serious reason to design the interface at it is and 
somewhat ignoring that it is already in place in a released version, I hereby 
suggest changing the signature to `V get(R rowKey, C columnKey)`, making use of 
already available type information to prevent unnecessary errors.

Original issue reported on code.google.com by j...@nwsnet.de on 12 Jul 2011 at 1:45

GoogleCodeExporter commented 9 years ago
Instead we've pushed changes to findbugs that flag this problem for you. It's 
the best we can do.

Original comment by kevinb@google.com on 13 Jul 2011 at 6:21

GoogleCodeExporter commented 9 years ago
Just for the record, what was the actual reason for the liberal argument types 
of `get`?

Original comment by j...@nwsnet.de on 14 Jul 2011 at 2:07

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
You might want to look for the reason Kevin already stated a few years back:
http://smallwig.blogspot.com/2007/12/why-does-setcontains-take-object-not-e.html

Original comment by ogregoire on 15 Jul 2011 at 7:46

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:09