Suppose I have a few variables:
public void foo() {
String name = "Bob";
String gender = "Male";
Integer age = 6;
String address = "some address";
}
How can I turn them into a Map<String, Object> like
Map<String, Object> map = new HashMap<>();
map.put("name", name);
map.put("gender", gender);
map.put("age", age);
map.put("address", address);
other than manually inserting them into the map. Can this be done using Reflection?
name,genderetc are local variables, and reflection can't be used for local variables. If they were fields it would be different.