Is there miss an equls method for class Context.Key in gRPC java

34 views
Skip to first unread message

Wang Tao

unread,
Jun 16, 2016, 9:16:48 AM6/16/16
to grpc.io
private Object lookup(Key<?> key) {
 
for (int i = 0; i < keyValueEntries.length; i++) {
   
if (key.equals(keyValueEntries[i][0])) { // here use an equals method?
     
return keyValueEntries[i][1];
   
}
 
}
 
if (parent == null) {
   
return null;
 
}
 
return parent.lookup(key);
}


Eric Anderson

unread,
Jun 16, 2016, 3:29:33 PM6/16/16
to Wang Tao, grpc.io
On Thu, Jun 16, 2016 at 6:16 AM, Wang Tao <cr3...@gmail.com> wrote:
private Object lookup(Key<?> key) {
 
for (int i = 0; i < keyValueEntries.length; i++) {
   
if (key.equals(keyValueEntries[i][0])) { // here use an equals method?

It is purposefully using reference equality. In earlier versions we overrode equals and used the Key name for equality. However, we swapped to using reference equality to allow users to have finer control over who can access the value (like with public/protected/private). If you don't have a reference to the Key, you can't get the value.

Would it be easier for you if it did override equals?
Reply all
Reply to author
Forward
0 new messages