I Wonder Why (Challenging)
Did you ever wonder why Java classes are defined the way they are? Why are certain inherited methods overridden and others not? For example, the == operator compares references, as does equals(Object o) inherited from Object. However, equals(Object o) can be, and often is, overridden. String overrides equals(Object o), but StringBuilder does not. When applied to String objects, equals(Object o) compares characters but the == operator compares references. This is not the case with StringBuilder where both == and equals(Object o) compare references.
a. Why do you think Java’s designers made this choice? Justify your answer.
b. How is this choice related to the immutability of String objects and/or the fact that the hashCode() method must assign the same value to “equal” objects. You may need to do a little research to answer this question.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.