Java Reflection Field Set setField(String field, Object value)

Here you can find the source of setField(String field, Object value)

Description

set Field

License

Apache License

Declaration

private static void setField(String field, Object value) throws NoSuchFieldException, IllegalAccessException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Field;

public class Main {
    private static Object packet;

    private static void setField(String field, Object value) throws NoSuchFieldException, IllegalAccessException {
        Field f = packet.getClass().getDeclaredField(field);
        f.setAccessible(true);//from  w w  w. j a  v a 2  s .c o m
        f.set(packet, value);
    }
}

Related

  1. setField(Object target, String name, Object value)
  2. setField(Object target, String name, Object value)
  3. setField(Object target, String name, Object value)
  4. setField(Object targetObject, String fieldName, Object value, boolean failIfError)
  5. setField(String field, Object object, Object value)
  6. setField(String fieldName, Object instance, Class instanceClass, Object value)
  7. setField(String fieldName, Object instance, Object value)
  8. setField(String name, Object target, Object value)
  9. setField(String name, Object target, Object value)