How can I get an Object from a method parameter of given type? Assuming I have:
public void methodWithParameters(MyClass object, OtherClass otherObject) {
//...
}
now i'm trying to get the object of MyClass type.
public Object getObject() {
Method method = //get methodWithParameters
Parameters[]parameters = method.getParameters();
for (Parameter parameter : parameters) {
if (parameter.getType().equals(MyClass)) {
return //object that was passed to methodWithParameters
}
}
}
Aucun commentaire:
Enregistrer un commentaire