As far as I know, we cannot do this in Java. Can we do this in scala?
Suppose the following method exists:
def insert(name:String, age:Int) {
// insert new user
}
Can I get the parameter names name
and age
in scala?
UPDATE
I want to do this because I want to bind method parameters automatically.
For example, this is a web application, it has some actions defined as:
class UsersController extends Controller {
def create(name: String, age: Int) {
}
}
The client clicked the submit
form button creating the user. The URL will be /users/create
with some send options.
On the server side, when we get the url with the name /users/create
, we will find the method create
in the controller UsersController
found now. Then I need to get the parameter names of this method, then we can get their values:
val params = getParamsFromRequest()
val method = findMethodFromUrl("/users/create")
val paramNames = getParamNamesOfMethod(method)
val paramValues = getValues(params, paramNames)
method.invoke(controller, paramValues)
, ?