"Combining var-args with EITHER widening or boxing in a method-matching scenario
Waiting for enlightenment....
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Waiting for enlightenment....
Martin Vanyavchich wrote:Your call is ambiguous. Methods themselves are perfectly fine.
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Waiting for enlightenment....
Waiting for enlightenment....
Waiting for enlightenment....
SCJP 6.0 96%
(Connecting the Dots ....)
Waiting for enlightenment....
SCJP6.0,My blog Ranchers from Delhi
SCJP6.0,My blog Ranchers from Delhi
in both the above two cases autoboxing is done from
1.) from int to long
2.) from int to Integer
intially in your code there is no widening...widening is done only after autoboxing from int to long
What your code is trying to do with this method is.....
static void wide_range(long... x){
System.out.println("long...");
}
it tries to autobox the int to long........
Waiting for enlightenment....
Prateek Rawal wrote:
Waiting for enlightenment.....
Prateek Rawal wrote:So, we can't combine var-arg with boxing and widening simultaneously,is it?
SCJP 6, OCMJD 6, OCPJWSD 6
I no good English.
Waiting for enlightenment....
Prateek Rawal wrote:Hey Martin,
A serious advice to you: Before replying to a thread, make sure you read earlier messages.......
SCJP6.0,My blog Ranchers from Delhi
Basically, the JLS is pretty vague when it comes to mixing var-args with overloading, and in fact, Sun documents even mention that you should try not mixing the two.
but if you want to invoke short method then do
class Humm {
static void wide_range(Short... x){
System.out.println("short...");
}
static void wide_range(Integer... x){
System.out.println("Integer...");
}
public static void main(String[] args) {
int i = 5;
wide_range((short)i,(short)i);
}
}
Waiting for enlightenment....
OCPJP(83%)
ankur trapasiya wrote:hey prateek..!! This is the conclusion that i found by trying so many examples and searching over the internet.
if you still confused then refer this
webpage
love demgracy, knowledge demogracy, open source and Java - OCPJP 76%
Consider Paul's rocket mass heater. |