September 2019
Intermediate to advanced
816 pages
18h 47m
English
Mainly, there are several solutions for obtaining the getters and setters of a class via reflection. Let's assume that we want to fetch the getters and setters of the following Melon class:
public class Melon { private String type; private int weight; private boolean ripe; ... public String getType() { return type; } public void setType(String type) { this.type = type; } public int getWeight() { return weight; } public void setWeight(int weight) { this.weight = weight; } public boolean isRipe() { return ripe; } public void setRipe(boolean ripe) { this.ripe = ripe; } ...}
Let's start with a solution that gets all the declared methods of a class via reflection (for example, via Class.getDeclaredMethods()). Now, ...