A few days ago I had an interview and there a few interesting questions occurred. Namely, the recruiter asked me meticulous questions. Some of them concerned the close relationship between HashCode and the collections, which are based on the above-mentioned mechanism.
The first question was more or less like: what impact does the quality of hashCode have on the work of hashMap? The question was not literally worded, but I think that the question was about performance.
The second question touched on the problem of modifying one of the value(s) of the hashMap pair(s) and the potential impact of this operation on performance and the problems that may arise from such a procedure. It wasn't explicitly stated how to modify the value, but I think it was a put() method. For instance, we have a pair in hashMap like ["Programming", 7]. What will happen if we modify the value 7 or "Programming".
The third question was open and sounded like this: How is the hashCode value calculated for an object without any fields.
For the second question I asked that:
we are not able to modify key of the pair because in the hashmap internal implementation key modifier is marked as final
and if we want to do it we should remove this particular pair and add it with desirable values.
I asked either that modifying the value of the pair (key-value) in hashMap has no impact on HashCode because we should base the calculation on the immutable keys like String but I was not able to realize if it was enough for the recruiter due to the fact that this interview was not face to face.
Honestly, this interview was a little bit confused because the recruiter was so enigmatic, that's why I would like to know if from your point of view you can see another bottom of this three questions and I could add some additional information in my response.
I would be grateful if you could suggest what could have been behind these enigmatic questions.