#cant override equals()

1 messages · Page 1 of 1 (latest)

lavish basinBOT
#

<@&987246399047479336> please have a look, thanks.

lavish basinBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

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.

compact sun
#

my syntax is identical

#

why wont it let me override

wanton forge
compact sun
#

idk how else im supposed to pass it in

wanton forge
compact sun
#

so i can use Point methods

wanton forge
compact sun
#

yeah

wanton forge
#

do you have java plugins enabled ?

compact sun
#

yeah

wanton forge
#

then click on the hints on the class header

#

then generate hashcode and equals

compact sun
#

just shows this

wanton forge
#

not the method

compact sun
#

ah

#

oh nice

wanton forge
#

can you show the generated code ?

compact sun
wanton forge
#

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

compact sun
#

I think it makes sense

wanton forge
#

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)

compact sun
#

I prefer instance of

wanton forge
#

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

compact sun
#

got it

#

the whole syntax is kind of weird

#

but ye

wanton forge
#

also note that float and doubles do a lot of rounding

#

so it will rarely be true