Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: get all method parameters as Object array

Is it possible to do this:

void foo(Bar b, FooBar fb){
    Object[] args=getArgs() //Contains the parameters b & fb
}

And if yes, how?

(I dont know the name and the number of parameters)

like image 560
flimmerkiste Avatar asked Mar 01 '26 14:03

flimmerkiste


1 Answers

No, Java does not support a simple, generic way to pack all the method arguments into an array. This is pretty standard for statically typed programming languages. It's generally dynamic languages like JavaScript and shell scripting languages that do allow retrieving all the arguments as an array.

like image 121
Nayuki Avatar answered Mar 05 '26 01:03

Nayuki