List of utility methods to do Reflection Field Set
void | setField(Object target, String name, Object value) Sets the new for field with given name. Assert.isNotNull(target); Assert.isNotNull(name); Field field = getField(target, name); if (field == null) { Class<?> targetClass = getTargetClass(target); throw new IllegalArgumentException(name + " in " + targetClass); try { ... |
void | setField(Object targetObject, String fieldName, Object value, boolean failIfError) Sets the fields value via reflection, this is useful in case there is no setter defined on the target object. try { Field f = targetObject.getClass().getDeclaredField(fieldName); f.setAccessible(true); f.set(targetObject, value); } catch (Exception e) { if (failIfError) { throw new RuntimeException("failed to set field", e); } else { ... |
void | setField(String field, Object object, Object value) set Field try { Field entryField = object.getClass().getDeclaredField(field); entryField.setAccessible(true); entryField.set(object, value); } catch (Exception e) { e.printStackTrace(); |
void | setField(String field, Object value) set Field Field f = packet.getClass().getDeclaredField(field); f.setAccessible(true); f.set(packet, value); |
void | setField(String fieldName, Object instance, Class instanceClass, Object value) set Field if (instanceClass == null) { throw new RuntimeException("NoSuchField: " + fieldName); try { Field field = instanceClass.getDeclaredField(fieldName); field.setAccessible(true); field.set(instance, value); } catch (NoSuchFieldException e) { ... |
boolean | setField(String fieldName, Object instance, Object value) set Field Field field = fieldFor(instance, fieldName);
return field != null && setField(field, instance, value);
|
void | setField(String name, Object target, Object value) set Field try { Class<?> targetClass = target.getClass(); Field field = targetClass.getDeclaredField(name); boolean unlocked = false; if (!field.isAccessible()) { field.setAccessible(true); unlocked = true; field.set(target, value); if (unlocked) { field.setAccessible(false); } catch (Exception e) { throw new RuntimeException(e); |
void | setField(String name, Object target, Object value) set Field Field field = null; Class<?> clazz = target.getClass(); do { try { field = clazz.getDeclaredField(name); } catch (Exception ex) { clazz = clazz.getSuperclass(); ... |
void | setField(T object, Field field, ResourceBundle bundle) set Field try { String value = bundle.getString(field.getName()); if (value != null) { field.setAccessible(true); field.set(object, value); } catch (MissingResourceException mre) { field.setAccessible(true); ... |
void | setFieldAccessible(Class> clazz, String... names) set Field Accessible try { Field field = getField(clazz, names); if (field != null) field.setAccessible(true); } catch (Exception e) { |