Java Utililty Methods Reflection Field Set

List of utility methods to do Reflection Field Set

Description

The list of methods to do Reflection Field Set are organized into topic(s).

Method

voidsetField(Field field, Object obj, String value)
Set field value using reflection.
Class<?> type = field.getType();
Object valueObject = convertValue(type, value);
if (valueObject != null) {
    field.set(obj, valueObject);
voidsetField(Field field, Object objToSet, Object value)
set Field
field.setAccessible(true);
try {
    field.set(objToSet, value);
} catch (IllegalArgumentException | IllegalAccessException e) {
    throw new RuntimeException(e);
voidsetField(Field field, Object target, Object value)
set Field
try {
    makeAccessible(field);
    field.set(target, value);
} catch (IllegalAccessException var4) {
    throw new IllegalStateException(
            "Unexpected reflection exception - " + var4.getClass().getName() + ": " + var4.getMessage());
ObjectsetField(Field field, Object target, Object value)
Set a field
if (field == null)
    throw new IllegalArgumentException("Null field");
try {
    field.set(target, value);
    return null;
} catch (Throwable t) {
    throw handleErrors("set", field, target, value, t);
voidsetField(Field field, Object target, Object value)
set Field
if (!Modifier.isPublic(field.getModifiers())) {
    field.setAccessible(true);
try {
    field.set(target, value);
} catch (IllegalAccessException iae) {
    throw new IllegalArgumentException("Could not set field " + field, iae);
voidsetField(Field field, Object target, Object value)
Set the field represented by the supplied Field field object on the specified Object target object to the specified value.
try {
    field.set(target, value);
} catch (IllegalAccessException ex) {
    handleReflectionException(ex);
    throw new IllegalStateException(
            "Unexpected reflection exception - " + ex.getClass().getName() + ": " + ex.getMessage());
voidsetField(Field field, Object target, Object value)
set Field
try {
    field.set(target, value);
} catch (IllegalAccessException ex) {
    throw new IllegalStateException(
            "Unexpected reflection exception - " + ex.getClass().getName() + ": " + ex.getMessage());
voidsetField(Field field, Object target, Object value)
Set the field represented by the supplied Field field object on the specified Object target object to the specified value .
try {
    boolean accessibled = makeAccessible(field);
    field.set(target, value);
    if (accessibled)
        field.setAccessible(false);
} catch (IllegalAccessException e) {
    throw new IllegalStateException("Could not access field: " + e.getMessage());
voidsetField(Field field, Object target, Object value)
set Field
try {
    field.set(target, value);
} catch (IllegalAccessException ex) {
    handleReflectionException(ex);
    throw new IllegalStateException(
            "Unexpected reflection exception - " + ex.getClass().getName() + ": " + ex.getMessage());
ObjectsetField(Field field, T newValue, Object instance)
set Field
Object old = null;
final boolean accessible = field.isAccessible();
if (!accessible) {
    field.setAccessible(!accessible);
old = retrieveField(field, instance);
field.set(instance, newValue);
field.setAccessible(accessible);
...