lundi 2 février 2015

Java Reflection Setter

I am trying to set the values of class member variable by using java reflection but during invocation of method it will stop and it doesn't throw any exception or error . It's irritating I am stuck here plz help me.................... Here is my code public class SMapper {



public void SetMapforvalues(Hashtable obj) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {

Field[] fields = this.getClass().getDeclaredFields();

for (Field field : fields) {

String fieldName = field.getName();
Object value = obj.get(fieldName);

if (value != null) {

Class<?> type = field.getClass();

if (type.equals(Integer.class)) {
Integer data = (Integer)value;
field.set(this, data);

} else if (type.equals(String.class)) {
String data = (String)value;
field.set(this, data);
} else if (type.equals(Double.class)) {
Double data = (Double) value;
field.set(this, data);
} else {

Method method = type.getMethod("SetMapforvalues");
Object methodreturn = method.invoke(value, obj);

}
}

}

}


}






Aucun commentaire:

Enregistrer un commentaire