Java Field.getByte(Object obj)
Syntax
Field.getByte(Object obj) has the following syntax.
public byte getByte(Object obj) throws IllegalArgumentException , IllegalAccessException
Example
In the following code shows how to use Field.getByte(Object obj) method.
//from ww w . j ava 2s. c o m
import java.lang.reflect.Field;
class MyClass {
public byte i = 10;
}
public class Main {
public static void main(String[] args) throws Exception {
Class<?> clazz = Class.forName("MyClass");
MyClass x = (MyClass) clazz.newInstance();
Field f = clazz.getField("i");
System.out.println(f.getByte(x)); // Output: 10
f.setByte(x, (byte)20);
System.out.println(f.getByte(x)); // Output: 20
}
}
The code above generates the following result.