aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes var...args Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "var...args" Watch "var...args" New topic
Author

var...args

karnatam narendraprasad
Ranch Hand

Joined: Mar 01, 2007
Posts: 30
hi friends,


class test
{
public static void main(String[] args)
{
test inst_test = new test();
inst_test.method ( 1 , 1 , 1);
inst_test.method( new Integer(1) , new Integer(2) , new

Integer(3) );
inst_test.method ( 1 , new Integer(5) );
inst_test.method ( new Integer(10) , 1 );
}

public void method( Integer... I )
{
System.out.println("Eye in the sky");
}

public void method( int... i )
{
System.out.println("Fly in the pie");
}

}

why its not compileing
an any one explaine


Thanks,
Narendra
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
Both methods match all invocations and neither is more specific than the other.
karnatam narendraprasad
Ranch Hand

Joined: Mar 01, 2007
Posts: 30
thanq,

you are saying that int,Integer take same values.

but

if we take like this ....

public void method(int a,Integer... b){
//some implementation
}
public void method(Integer a,int... b){
//some implementation
}

then these two also same........
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
The rules for the most specific method when it comes to var-args is pretty complex.

I think the best advice would be not to overload var-args methods.

You can read the details in the Java Language Specification 15.12.2.5.
[ March 16, 2007: Message edited by: Keith Lynn ]
 
jQuery in Action, 2nd edition
 
subject: var...args
 
Similar Threads
re: ambiguous method calls
Ambiguity in calling Varargs
overloading
Boxing vs VarArgs
unexplainable result