Jrcastro Ribeiro wrote:
Completely unrelated, but that code makes me cry. I hope that's been generated by your
IDE, because I'd hate to have you waste time on writing such verbose code.
Unless you are using
Java 6,
you should make use of java.util.Objects:
I've just halved the number of lines of code of those two methods (
equals went from 53 to 19, and that is with added { and }!), and made it more readable at the same time.
Note the calculation of
hashCode of
ativo.
Boolean.valueOf(ativo) always returns either
Boolean.TRUE or
Boolean.FALSE, so this does not require any new objects. Java 8 has added static
hashCode methods to all primitive wrapper classes, making it a lot easier to write
hashCode methods. Especially for
long,
float and
double it was quite verbose. Compare: