#cant override equals()
1 messages · Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
It's Object, not Point
yeah but Point is an object
idk how else im supposed to pass it in
doesn't matter, you must use Object
is there a way to cast it afterwards back to point
so i can use Point methods
are you using vascode ?
yeah
do you have java plugins enabled ?
yeah
can you show the generated code ?
so as you can see
first it checks this == obj
this is not needed but is a shortcut
since if it is true, then it's the same object and so it is equal
then it checks to null, if the other is null, then it can't be equal
I think it makes sense
then it compares the classes
so it checks if both are the class Point
note that there are two approaches
getClass() != obj.getClass()
or
!(obj instanceof Point)
I prefer instance of
the second is also true if it is an inherited class from Point
and then there is a cast
and then the fields checks
also note that here it is using a weird method to compare the floats
the reason is because of NaN
it's a very special case
but NaN == NaN is false
so if you use ==, it wouldn't work
so it converts to bits first
but that's a case specific to float and double, usually you use == or .equals
@compact sun