Harry Henriques wrote:
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Andre Enimot wrote:I think the reason for the "ambiguity" error that Henry gets is not because static methods are shadowed, but because the compiler can not decide which method to call. When one method is commented the ambiguity is resolved. Similar error would occur if one calls two overloaded methods that take say Integer... and int... with a Integer (or int) argument.
You're stating the obvious.. why aren't the signatures ok?Method with varargs is called only when no other method signature matches the invocation.
in your case the signatures are same.
Good question though i also didnt know about this behaviour. ty
For every winner, there are dozens of losers. Chances are you're one of them.
Ankit Garg wrote:
Harry IMHO, Vararg9 should've compiled fine. You are not overloading int... and Integer... so the code should've compiled as per me. Maybe its a bug in the JVM.
Kai Witte wrote:
Neal Gafter started the implementation based on a preliminary (and as far as I know unpublished) vararg spec. According to that spec the check for the more specific method used similar rules to the ones in the check for method applicability, taking boxing into account. The author of the official JLS wrote it differently: Simpler, but less intuitive, without taking boxing into account. The result is that the official 1.5.0 RI does not work in full compliance with the JLS, which was "fixed" in 1.5.0_01.
Kai Witte wrote:
JLS 15.12.2.5, "Choosing the Most Specific Method" is relevant here. The subsection specifically for varargs is simple in our case, because in our case n = 1 and k = 1. Insert that and the description becomes quite simple. Basically it sais that the vararg part of a method is not relevant for choosing the most specific method. So neither method is more specific, and certainly not strictly more specific, than the other one.
Kai Witte wrote:
JLS 15.12.2.5, "Choosing the Most Specific Method" is relevant here. The subsection specifically for varargs is simple in our case, because in our case n = 1 and k = 1. Insert that and the description becomes quite simple. Basically it sais that the vararg part of a method is not relevant for choosing the most specific method. So neither method is more specific, and certainly not strictly more specific, than the other one.
@Ankit: the code is not ok... compilation fails
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Consider Paul's rocket mass heater. |