Since I don't have any great skills in math, I ask you if there exists any algorithm that I should use for a class which probably will change in the future.
Consider following scenario:
Class "Roles" has following fields:
private boolean admin;
private boolean printer;
After some weeks I decide to add a role "guest":
private boolean admin;
private boolean printer;
private boolean guest;
After some weeks I decide to remove the role "printer";
private boolean admin;
private boolean guest;
Since I will persist the hashcode in a database, I must be 100% sure that all versions of this class generates unique hashcodes.
Maybe this is not a problem, I have always used the one provided in the Eclispe IDE source generator.
Can you please tell me if I am safe with the Eclipse IDE (Indigo) Java version >= 6 method or give me some other advices regarding this topic. I am sure this is a very common thing.
Thanks in advance
Don't do that. The result of
hashCode
isn't meant to be persisted. In particular, from the docs:Next:
Hash codes aren't meant to be unique, either... they very often won't be. Okay, you've only got 5 bits of data in your case, but in general that's not the case...
It sounds like you have different requirements from the normal ones for
Object.hashCode()
- so you shouldn't expect any autogenerated implementation to know about your special requirements. I suggest you state exactly what your requirements are, and we can work out what to do...