• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need Help

 
Madan Mohan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could someone please explain me how boxing and var - args work...
 
Kenneth Lomvey
Ranch Hand
Posts: 94
 
Rajshekhar Paul
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to give an idea -

1. through var-args you can send zero as well as more than zero argument of same type to a method which has only one parameter(), i.e. var-arg parameter. a method can have only one var-arg parameter and it should be the last parameter if there are more than one parameter for that method.

2. boxing is used to have the primitive specific behavior in a wrapper class object.
 
Madan Mohan
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raj,

Could you please explain me this paragraph with some example..I am not able to get it

"through var-args you can send zero as well as more than zero argument of same type to a method which has only one parameter(), i.e. var-arg parameter. a method can have only one var-arg parameter and it should be the last parameter if there are more than one parameter for that method."
 
Rajshekhar Paul
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure.



Hope, it helps you.
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me also try to explain you what raj meant

void method(String... args, int... i) //not allowed, cannot have more than one var-args in a method

-------------------------------------------------------------------------

void method(String... args, int i) //not allowed, var-arg must be the last parameter so the correct code would be

void method(int i, String... args)

-------------------------------------------------------------------------
void method(String... args)

now you can call this method as

method(); //no arguments
method("a"); //1 argument
method("a", "b"); //2 argument

and so on. i.e. you can pass any number of arguments to this method...

[Edit: Oops! I was not quick enough]
[ December 05, 2008: Message edited by: Ankit Garg ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic