There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Brian Mart wrote:I understand that .equals() compares the content of the field, while == compares the hexcode location of an object,
but there are still some things troubling me. Specifically, if I want to check for equality of the age of something, would I use == since it is an int and Java would read all equal numbers as the same? I know a String is always compared with .equals(), and a boolean value is compared with ==, but what about doubles, ints, and floats? Let me know if this question is too vague and I will provide some example code. Thanks for your help!
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
The equals method tells you if two objects have the same contents.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Ralph Cook wrote:And you are right, equals() can be defined to mean different things...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
look! it's a bird! it's a plane! It's .... a teeny tiny ad
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|