List of utility methods to do Reflection Field Set
void | setField(final Object parent, final String name, final Object obj) set Field try { final Field f = findField(parent.getClass(), name); f.setAccessible(true); f.set(parent, obj); } catch (final Exception e) { e.printStackTrace(); |
void | setField(java.lang.Object toObj, String tcFieldName, java.lang.Object toNewValue) set Field try { Field loField = toObj.getClass().getDeclaredField(tcFieldName); loField.setAccessible(true); loField.set(toObj, toNewValue); } catch (IllegalArgumentException ex) { throw new RuntimeException(ex); } catch (IllegalAccessException ex) { throw new RuntimeException(ex); ... |
void | setField(Object instance, String fieldName, Object value) Sets the value of the fieldName in a given instance by reflection.
Field field = instance.getClass().getDeclaredField(fieldName); field.setAccessible(true); field.set(instance, value); |
void | setField(Object instance, String name, Object obj) set Field try { Field f = instance.getClass().getDeclaredField(name); f.setAccessible(true); f.set(instance, obj); } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) { throw new RuntimeException(e); |
void | setField(Object instance, String sField, Object value) set Field Field field = instance.getClass().getDeclaredField(sField); field.setAccessible(true); field.set(instance, value); |
void | setField(Object item, Field f, Object value) set Field try { f.setAccessible(true); f.set(item, value); } catch (Exception e) { e.printStackTrace(); |
void | setField(Object o, String fieldName, Object inject) set Field Field field = getAccessibleField(fieldName, o.getClass()); try { field.set(o, inject); } catch (IllegalAccessException e) { e.printStackTrace(); |
void | setField(Object o, String fieldName, Object value) set Field try { Field field = null; try { field = o.getClass().getField(fieldName); } catch (NoSuchFieldException e) { try { o.getClass().getDeclaredField(fieldName).setAccessible(true); field = o.getClass().getField(fieldName); ... |
Object | setField(Object o, String fieldName, Object value) Sets the value of a field on an object Object oldVal = null; try { final Field field = getFieldInt(o.getClass(), fieldName); field.setAccessible(true); oldVal = field.get(o); field.set(o, value); } catch (Exception e) { throw new RuntimeException("Cannot get value of field " + fieldName, e); ... |
void | setField(Object o, String name, Object value) set Field try { field(o, name).set(o, value); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); |