Is .equals() redefined for primitive types?
The object is or cointains a primitive type either String, int, short, and boolean.
I'm implementing this: object.equals(primitive type) hoping that is should be able to determing that object "Hello" is equal to String "Hello", or object "32" short is equal to Short "32", same for boolean, and int.
Most of the type the equals compares identity and not state. So I am wondering if the equals() is overrided by the primitive types.
Re: Is .equals() redefined for primitive types?
Java primitives are not objects and have no member methods associated with them. However, they can be auto-boxed into wrapper classes such as Integer, Short, etc. These are full objects and have equals() overridden to compare state. You'll have to check the definition if a Short with value 32 is equal() to an Integer with value 32, I don't remember off the top of my head if this is true or not.
Strings are not primitives in Java, but full objects and have .equals() overridden correctly to compare state.