Here you can find the source of setField(String field, Object value)
private static void setField(String field, Object value) throws NoSuchFieldException, IllegalAccessException
//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); } }