Java Reflection Java Java API
java.lang.reflect.Field
public void setByte(Object obj, byte b) throws IllegalArgumentException, IllegalAccessException
Sets the value of a field as a byte on the specified object.
byte
package com.logicbig.example.field;import java.lang.reflect.Field;public class SetByteExample { private byte myByte; public static void main(String... args) throws NoSuchFieldException, IllegalAccessException { Field f = SetByteExample.class.getDeclaredField("myByte"); SetByteExample instance = new SetByteExample(); byte b = 10; f.setByte(instance, b); System.out.println(f.getByte(instance)); }}
10