I want to insert a value to an Object
variable without using the setters. How can if be possible.
This is an example
Class X{
String variableName;
// getters and setters
}
Now i have a function which contains the variable name
, the value to be set
and an Object of the Class X
.
I am trying to use a generic method to set the value to the Object(objectOfClass) with the value i have passed(valueToBeSet
) in the corresponding variable(variableName
).
Object functionName(String variableName, Object valueToBeSet, Object objectOfClass){
//I want to do the exact same thing as it does when setting the value using the below statement
//objectOfClass.setX(valueToBeSet);
return objectOfClass;
}