Reputation: 3503
I am considering using Eclipse generated HashCode and I have a basic doubt (using it for the first time). Why does the hashCode in the below code snippet use the result field? I feel it is redundant and would like to understand what possible reasons could cause it to being there
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((projectId == null) ? 0 : projectId.hashCode());
return result;
}
Upvotes: 0
Views: 51
Reputation: 895
Donald Knuth said "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil".
Regarding your question: java JIT compiler is so smart, that it will remove all unnecessary variables and calculations.
So you should concentrate on writing understandable, readable and maintainable code. You have to fix performance problems when they appear.
Upvotes: 1