by Paweł Chudzik

Final fields


Private final field modification is possible and it doesn’t require a lot of work. Since you should not use this mechanism in real life there are cases when it is useful. For example this how is Hibernate using this to hydrate final entity fields.

But when using final fields with Hibernate you should be extra careful how you declare them.

3 Dec 2016

Test methods coupling


Sometimes when unit tests setup is complex we are tempted to take shortcuts and write single setup for all tests which will save as few keystrokes. In the time of writing the test it might feel like a good idea to configure complex unit test setup and reuse it in all test. This way we avoid code duplication and we create a more condensed test. This approach looks good only in the time of the writing tests. Then there is a time when unit tests must be maintained. This is the time when you usually realize that saving few keystrokes wasn’t such a good idea.

29 Oct 2016

Consistent return of hashCode in java


HashCode and equals implementations are hard. Usually, it’s tricky to properly implement hashCode and equals method to fully fulfill contract from Java documentation. I’m going to focus on just one the point from the hashCode contract:

whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer.

Read it already? Do it again. Let it sink and think about impact of “hashCode method must consistently return the same integer”

19 Oct 2016