This program runs as a naive programmer would expect, but it might surprise some
ID: 3680099 • Letter: T
Question
This program runs as a naive programmer would expect, but it might surprise someone who knows that the != operator in Java compares object identities, not their values. If you change the initial values to 1001 and 1010, the code behaves the way a naive programmer would expect while it would surprise a naive programmer.
Obviously the implementors of class Integer did some extra work to make it behave as a naive programmer would expect so long as the integer values were within a small range. Don't worry about finding the bounds of the range.
The heavy lifting required to help class Integer satisfy naïve programmers must be done by addint some static data structures to the class and adding special code to the Integer() constructor. Suggest an appropriate static data structure to add to the class. (Hint: One static declaration is all it takes.) --- in Java
Explanation / Answer
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
with classes there is often an option to make a direct, non-interface call to the method which implements the interface.
Note that the interface takes an erased Object parameter, as required by the current rules of Java. In the context of the value type, we allow the type parameter (T in Comparable<T>) to bind to the value type Bignum and thus bridge the box method through to the value method compareTo. The language rules which govern this are not yet defined in detail.
We expect every value to implement an ad hoc interface or abstract super type that looks something like this:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.