Let's say I have following class:
@Getters
public class Metrics {
private String length;
private String width;
private String height;
private String volume;
public void changeMetric(string newValue, string metricVariable) {
/*
based on metricVariable value (which can be "length", "width", "height" or "volume")
change the corresponding private variable with the newValue.
*/
}
}
changeMetric
can be implemented using switch case, however it would take lot of code incase the number of private variables is large.
Is there any annotation, framework or other solution, which can directly change the corresponding private metricVariable
without iterating to each one of them?