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
Let's use this issue to talk about "Decide some convention about written equals/hashcode in Leshan".
If you interested about that you should first read : How to Write an Equality Method in Java
My current opinion :
we should probably use Objects.hash and Objects.hash
Use of this 3 a valid behavior :
1. Use classic getClass() != obj.getClass() + making the class final : this is the simple way but I do not like too much the idea I prefer to let user being able to extend class.
2. Use an instanceof + make hashcode/equals final : this is simple enough and this allow to extend the class but not to customize equals behavior...
3. Use the canEqual method, which is a bit unusual but sounds to solve all problems.
Should we encourage to use 3. in all code base ?
The text was updated successfully, but these errors were encountered:
Investigating on NPE in
LwM2mPath.hashcode()
find at #1502.I decide to add unit tests to check the bug before to fix it.
I found that library to do that job : EqualsVerifier.
Good news : it does a very good job.
Bad news: this is more complicate than expected to implement good custom
equals
/hashcode
method.We should :
equals
/hashcode
methods and add a corresponding test based on EqualsVerifier.equals
/hashcode
in Leshan.equals
/hashcode
if needed.Let's use this issue to talk about "Decide some convention about written
equals
/hashcode
in Leshan".If you interested about that you should first read : How to Write an Equality Method in Java
My current opinion :
we should probably use
Objects.hash
andObjects.hash
Use of this 3 a valid behavior :
1. Use classic
getClass() != obj.getClass()
+ making the class final : this is the simple way but I do not like too much the idea I prefer to let user being able to extend class.2. Use an
instanceof
+ make hashcode/equals final : this is simple enough and this allow to extend the class but not to customize equals behavior...3. Use the
canEqual
method, which is a bit unusual but sounds to solve all problems.Should we encourage to use 3. in all code base ?
The text was updated successfully, but these errors were encountered: