[英]HashCode generation by Eclipse using redundant result field
I am considering using Eclipse generated HashCode and I have a basic doubt (using it for the first time). 我正在考虑使用Eclipse生成的HashCode,但我有一个基本的疑问(第一次使用它)。 Why does the hashCode in the below code snippet use the result field?
为什么下面的代码片段中的hashCode使用结果字段? 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;
}
Donald Knuth said "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil". 唐纳德·克努斯(Donald Knuth)说:“我们应该忘记效率低下的问题,大约有97%的时间是这样:过早的优化是万恶之源”。
Regarding your question: java JIT compiler is so smart, that it will remove all unnecessary variables and calculations. 关于您的问题:Java JIT编译器非常聪明,它将删除所有不必要的变量和计算。
So you should concentrate on writing understandable, readable and maintainable code. 因此,您应该专注于编写可理解,可读和可维护的代码。 You have to fix performance problems when they appear.
您必须解决出现的性能问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.