Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing variable parameters to a method

Hi is there any way for me to pass variable arguments to a method?

public void unMarshalling(String type, int number){

}

So that instead of int, I can make my method such that I am able to pass in float, double, string and other primitive data types(+ string). Any simple examples will be deeply appreciated! Thanks alot!

like image 749
Laughy Avatar asked May 08 '26 18:05

Laughy


1 Answers

Try this:

public void unMarshalling(Object ... params) {

}

Now you can pass any number of arguments of any type:

unMarshalling(23);
unMarshalling("Hello");
unMarshalling("Hello", 45.3);
like image 124
craftsman Avatar answered May 10 '26 08:05

craftsman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!