List of utility methods to do Reflection Field Set
void | setField(Class> clazz, Object obj, String fieldName, Object value) Set the value of a field to value. try { Field field = clazz.getDeclaredField(fieldName); boolean oldAccess = field.isAccessible(); field.setAccessible(true); field.set(obj, value); field.setAccessible(oldAccess); } catch (Exception e) { e.printStackTrace(); ... |
void | setField(Class> ownerClass, Object owner, String fieldName, Object newValue) set Field Field f; try { f = ownerClass.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { throw new RuntimeException(e); f.setAccessible(true); try { ... |
void | setField(Class> target, Class> fieldType, int index, Object obj, Object value) set Field try { getField(target, fieldType, index).set(obj, value); } catch (Exception ex) { ex.printStackTrace(); |
void | setField(Class set Field try { Field field = clazz.getDeclaredField(fieldName); field.setAccessible(true); field.set(instance, value); } catch (SecurityException e) { handleException(e); } catch (NoSuchFieldException e) { handleException(e); ... |
void | setField(Class Set the field of a given object to a new value with reflection. try { Field field = getField(clazz, instance, fieldName); field.set(instance, value); } catch (IllegalAccessException e) { throw new RuntimeException(format("Could not set value to field '%s' for instance '%s' of class '%s'", fieldName, instance, clazz.getName()), e); |
void | setField(Field f, Object instance, Object value) set Field try { boolean oldAccessible = f.isAccessible(); boolean shouldSetAccessible = !Modifier.isPublic(f.getModifiers()) && !oldAccessible; if (shouldSetAccessible) { f.setAccessible(true); f.set(instance, value); if (shouldSetAccessible) { ... |
void | setField(Field f, Object this_, Object value) Sets field with specified value in spite of access permission. try { f.setAccessible(true); f.set(this_, value); } catch (IllegalAccessException e) { throw new AssertionError(e); |
void | setField(Field field, @Nullable Object instance, Object thing) set Field Object fieldAccessor = newFieldAccessor.invoke(reflectionFactory, field, false); fieldAccessorSet.invoke(fieldAccessor, instance, thing); |
void | setField(Field field, Object classWithField, Object value) set Field try { field.set(classWithField, value); } catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); |
boolean | setField(Field field, Object instance, Object value) Sets the specified field to the specified value in the instance. if (field == null) { System.err.println("Null field"); return false; try { field.set(instance, value); } catch (Exception e) { System.err.println(field.getType() + " not assignable from " + value.getClass()); ... |