I have a question about HASHCODE.

Asked 2 years ago, Updated 2 years ago, 23 views

I have a question while studying HASHCODE.

If you look at the code above, I'm overriding hashCode()

It is possible to convert the string hash into an int-type and return it with the return hash.hashCode().

How can I recall hashCode() before overriding?

java

2022-09-22 19:55

2 Answers

return hash.hashCode();

Are you curious about this part?

This code does not get the hashCode of super.

String hash = name + id + job;
return hash.hashCode();

You get the hashCode of the String-type instance that you created in the upper row. Overriding here is meaningless except to overwrite the method name.

When you ask questions, please write the code in text instead of screenshots. Don't forget to use code blocks.


2022-09-22 19:55

Does hashCode() before overriding mean hashCode, a method of parent class? The method of the parent class is

super.method name (this)

You can invoke it as in . In this case, it would be super.hashCode(this).


2022-09-22 19:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.