That was how the code looked in pre-Java 5 versions, when generics were not there. This also shows that the book you're referring is toooooo old. Please avoid.
Why would my book say that Integer's compareTo has an Object parameter?
-
04-07-2023 - |
문제
I'm preparing for the AP Computer Science Exam and I'm confused by my text's discussion of the Integer
class.
The text defines Integer
's compareTo
as follows:
int compareTo(Object other)
It made since to me at first that it would have an Object
parameter because I thought that was the only way it could implement Comparable
. However, I ended up looking at the Integer
class in Eclipse and I noticed that it uses generics for Comparable
and thus defines compareTo
with an Integer
parameter.
Is this a mistake in my book? It led me to believe that it was casting the Object
to an Integer
in the method, which is wrong (and makes a difference on the exam). Am I missing something here?
해결책
제휴하지 않습니다 StackOverflow