• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

var...args

 
karnatam narendraprasad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both methods match all invocations and neither is more specific than the other.
 
karnatam narendraprasad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic