Home > JAVA > Method with var-args

Method with var-args

Rules for var-args:

  1. When you declare a var-arg parameter, you must specify the type of argument(s) this parameter of your method can receive.
  2. To declare a method using var-arg parameter, you follow thw type with an ellipsis (…), a space and then the name of the array that will hold the parameter recieve.
  3. It’s legal to have other parameters in a method that uses a var-arg.
  4. The var-arg must be the last parameter in the method’s signature, and you can have only one var-arg in a method.
void doSomething(int... a) { }
void doSomethind2(String a, int... b) { }

void doSomething3(int... a, int b) { }
void doSomething4(int... a, int... b) { }

Categories: JAVA
  1. No comments yet.
  1. July 1, 2014 at 2:00 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: