Java Reflection Java Java API
java.lang.reflect.Field
public byte getByte(Object obj) throws IllegalArgumentException, IllegalAccessException
Gets the value of a static or instance byte field. The provided 'obj' is the object to extract the byte value from (should be null for static fields).
byte
package com.logicbig.example.field;import java.lang.reflect.Field;public class GetByteExample { private static byte aStaticByte = 2; private byte aByte; public GetByteExample(byte aByte) { this.aByte = aByte; } public static void main(String... args) throws NoSuchFieldException, IllegalAccessException { GetByteExample obj = new GetByteExample((byte) 10); Field field = obj.getClass().getDeclaredField("aByte"); byte aByte = field.getByte(obj); System.out.println(aByte); Field field2 = GetByteExample.class.getDeclaredField("aStaticByte"); byte aByte2 = field2.getByte(null); System.out.println(aByte2); }}
102