I am seeing a strange issue. I have an object, which has a few instance variables, one of which is numeric. This object came out of a socket using ObjectInputStream's readObject(), so it should have been deserialized. However, when i compare it with another object which has the exact same number for that field, using == , it doesn't match. Note: I am not comparing objects, just the integer instance variable, using a getter. Print statements just before the comparison, show that they're exactly the same.
System.out.println("New book id:"+newBook.getId());
for (Book p: listOfBooks) {
System.out.println("CurrentBook's id:"+p.getId());
if (newBook.getId() == p.getId()) {
System.out.println("Matched CurrentBook's id:"+p.getId())
}
}
Thanks Ted Hopp, yes, i guess the behaviour is inconsistent for Integer comparisons with ==. I realised that the fields were Integer, not int, and it worked before, so was very confusing why it no longer worked.