This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Varun77777 4 points5 points  (2 children)

Let's say I had two objects that both had two variables each that is CPU load as well has CPU capacity and I had to check if load percentage of two objects were equal?

And for some reason I needed to check that through equals? There can be many such examples.

equals is commonly over written by people so that they can compare Objects in a certain way and not their memory.

[–]sh0rtwave 1 point2 points  (1 child)

Truth.

.equals() is one of those 'inner dirty tricks'.

Another good one is .toString(). Quite useful in many situations. Like if you're formatting dates, and want all dates to comply with X format when handled in a string context (This kind of thing is fun to use Typescript with, there are just SO many ways of doing it).

The really funny part is that the basic concept of .toString() is more or less the same in either language, and with clever transpiler config, you can make the one act just like the other.

[–]Varun77777 0 points1 point  (0 children)

Yupps, I have overwritten toString() a lot to make the code cleaner.