Forums Register Login

overloading generic methods

+Pie Number of slices to send: Send
Hi guys. I have two questions about generic method overloading.

With regard to this code:



(a) When methods 1 and 3 are commented in, compiler complains about 'call 2', presumably because Number implements Comparable. If I comment out 'method 1', the compiler chooses the method with the narrower upper bound. Is there a rule about overloading generic methods to be deduced from that? Does this have something to do with 'covariance'?

(b) When methods 3 and 4 are commented out the autoboxing of calls 2 and 3 works fine, however when 3 and 4 are in (and method 1 out per a), call 2 fails with:



and call 3 with:



If I explicitly box them myself it works as expected. That seems strange to me.

Thanks.
[ June 21, 2008: Message edited by: Mike Mitchell ]
"I know this defies the law of gravity... but I never studied law." -B. Bunny Defiant tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 836 times.
Similar Threads
Problem in Generic Method Declaration
Generics Doubt
Simple J2SE 5.0 Tiger Notes
Generic Interface Example
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:32:03.