Calling Method maximum
In main
(lines 6–14), line 9 calls maximum
with the integers 3
, 4
and 5
. When the compiler encounters this call, it first looks for a maximum
method that takes three arguments of type int
. There’s no such method, so the compiler looks for a generic method that can be used and finds generic method maximum
. However, recall that the arguments to a generic method must be of a reference type. So the compiler autoboxes the three int
values as Integer
objects and specifies that the three Integer
objects will be passed to maximum
. Class Integer
(package java.lang
) implements the Comparable<Integer>
interface such that method compareTo
compares the int
values in two Integer
objects. Therefore, Integer
s are valid arguments to method ...
Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.