Java Field.getChar(Object obj)
Syntax
Field.getChar(Object obj) has the following syntax.
public char getChar(Object obj) throws IllegalArgumentException , IllegalAccessException
Example
In the following code shows how to use Field.getChar(Object obj) method.
/*w w w. j a va 2 s . co m*/
import java.lang.reflect.Field;
class MyClass {
public char i = 'c';
}
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.getChar(x));
f.setChar(x, 'a');
System.out.println(f.getBoolean(x));
}
}
The code above generates the following result.