I am trying to implement program that will create an array out of the fields of a certain class and then access each field
I have the following class:
public class Example {
public int[] a = {1,2,3};
public int[] b = {1,1,1};
public int[] c = {2,2,2};
}
In a different class I want to access all of these fields and place them into the array "testArray"
import java.lang.reflect.Field;
public class Test {
Example t = new Example();
Field[] testArray = t.getClass().getFields();
for (Field elem: testArray) {
// access the fields
}
}
How can I access the fields this way?
NOTE: for some reasone this gives me an error of Syntax error on token ";", { expected after this token