I have a very strange behaviour I can not explain at all. Maybe it is just some Java related trickery I do not understand, I don’t know. Here the code
private void updateEntity(Entity linked, Entity solved) {
EntityId linkId = linked.get(Link.class).getLink();
System.out.println("XXX LINKED " + linked);
System.out.println("XXX SOLVED " + solved);
System.out.println("YYY LINKID " + linkId + "==" + solved.getId());
if (linkId == solved.getId()) {
System.out.println("HEY HO!");
solveQuests(linked, solved);
}
}
And the output is this
XXX LINKED Entity[EntityId[85], values=[Link[EntityId[86]], Quest[Power]]]
XXX SOLVED Entity[EntityId[86], values=[Solved, Solution[Power]]]
YYY LINKID EntityId[86]==EntityId[86]
I can not understand why the
if (linkId == solved.getId()) {
is not true?! If it were true I would also see the “HEY HO!”
The only thing which works so far is
if (linkId.equals(solved.getId())) {
I guess it then makes a string compare of the toString results of the both, a little backward if you ask me.
Can somebody explain me what is going on or what I do not see which is obvious to the rest of the world?!