That is luck. You might have collisions in future. You could consider the identity Hash Code, but you should check carefully whether that will give unique results.nimo frey wrote:Oh, actually I have no collisions . . .
nimo frey wrote:Oh, actually I have no collisions - all my instances are identifiable via the string version of the hashCode.
So what should I use instead? Should I override the toString-Version for identification?
nimo frey wrote:
I guess, I cannot use the
UUID a = UUID.randomUUID();
When I generate a UUID for the instance x and the client sends that UUID back to me, the instance x is no more binded to that UUID.
So I cannot compare it with the servers UUID as generating a new one for the instance x results in another UUID.
Maybe, this is the right thing to do:
UUID b = UUID.fromString(this.toString());
It is if you make that a field of the object.
I like JV’s suggestion of an automatically incremented field.
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
|