List of utility methods to do Reflection Field Value Set
void | setFieldValue(Field field, Object obj, Object value) set Field Value if (field != null) { try { field.set(obj, value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); |
void | setFieldValue(Field field, Object object, Object value) set Field Value try { field.set(object, value); } catch (IllegalAccessException e) { |
boolean | setFieldValue(Field field, Object object, Object value) set Field Value try { field.set(object, value); return true; } catch (IllegalAccessException e) { return false; |
void | setFieldValue(Field field, Object target, Object value) set Field Value try { field.setAccessible(true); field.set(target, value); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Cannot access (set) " + "[" + field + "] field in target [" + target + "]. " + "Reason: " + e.getMessage(), e); |
void | setFieldValue(Field field, Object value, Object instance) set Field Value boolean accessible = field.isAccessible(); if (!accessible) { field.setAccessible(true); try { field.set(instance, value); } catch (Exception ex) { throw new RuntimeException(ex); ... |
void | setFieldValue(Field field, Object value, Object target) set Field Value boolean declaredAccessible = field.isAccessible(); if (!declaredAccessible) { field.setAccessible(true); field.set(target, value); if (!declaredAccessible) { field.setAccessible(false); |
void | setFieldValue(final Class extends Object> clazz, final String fieldName, final Object fieldValue) Sets a new value of a static field. assert clazz != null && fieldName != null; final Field field = getField(clazz, fieldName); field.setAccessible(true); field.set(null, fieldValue); |
void | setFieldValue(final Field field, final Object instance, final Object value) Sets the value of a Field , making it accessible if required. makeAccessible(field); if (!Modifier.isStatic(field.getModifiers())) { Objects.requireNonNull(instance, "No instance given for non-static field"); try { field.set(instance, value); } catch (final IllegalAccessException e) { throw new UnsupportedOperationException(e); ... |
void | setFieldValue(final Field field, final Object obj, final Object value) set Field Value try { field.set(obj, value); } catch (IllegalAccessException e) { throw new IllegalStateException(String.format("Failed to set field %s to %s", field, value), e); |
void | setFieldValue(final Field field, final Object value, final Object object) set Field Value if (!field.isAccessible()) {
field.setAccessible(true);
field.set(object, value);
|