Reflections: What am I doing wrong here?
Given the object:
publicclass TestObject
{
public Object[] oArray;
publicint[] iArray;
}
and the code
TestObject to =new TestObject();
Field objectArrayField = to.getClass().getField("oArray");
Object oArray = Array.newInstance(objectArrayField.getType(), 0);
objectArrayField.set(to, oArray);
Field intArrayField = to.getClass().getField("iArray");
Object iArray = Array.newInstance(intArrayField.getType(), 0);// <-- Exception on this line
intArrayField.set(to, iArray);
I am getting the following exception:
java.lang.IllegalArgumentException
at sun.reflect.UnsafeObjectFieldAccessorImpl.set(Unknown Source)
at java.lang.reflect.Field.set(Unknown Source)
at com.efw.cp.ObjectParser.main(ObjectParser.java:151)
For the life of me, I can't see what I am doing wrong. This always fails whether the int[] array is defined to an array or defined to be null.
Any ideas?

