I have the following code and this code the casting is hard-coded (Person) Since object is generic type there is a way to get it during run-time with reflection ?
I don’t have the classes type and I get it just during Runtime (can be many different class)
but all the classes have the same method setId,how I can do it ?
List<Object> listClsObj
for (Object object : listClsObj) {
((Person)object).setId(null);
}
I tried with (object.getClass().setId(null); and I got sytax error and also tried with
Class<?> clazz = object.getClass();
(clazz).setId(null);
and also get syntax error (maybe I didnt do it well ),how should I handle it assume that I dont know the class type?
You can try with the following code