The generated equals() method does something that I find very surprising. It accesses the passed Objects private methods!
public boolean equals(Object o)
if (this == o) return true;
if (!(o instanceof Venue)) return false;
final Venue venue = (Venue) o;
if (!city.equals(venue.city)) return false;
if (!name.equals(venue.name)) return false;
if (!state.equals(venue.state)) return false;
I've been coding Java for years and always thought that private members cannot be accessed from anywhere except from within the same Object's code (i.e. they are encapsulated)
But this tells me that other Objects of the same class can also access these private fields.
Am I the only one surprised by this? Can someone point to some documentation explaining this?
And also, is this considered good style in general? I can see that in an automatically generated equals you would need to use private fields but otherwise this seems like dangerous style.