Java Class java.lang.reflect.Array provides a set of tools for creating an array dynamically. However in addition to that it has a whole set of methods for accessing (get, set,
Regarding the set...()
methods, they do provide some use:
Object a = new byte[1], b = new short[1], c = new int[1], d = new long[1];
Array.setByte(a, 0, (byte)1);
Array.setByte(b, 0, (byte)1);
Array.setByte(c, 0, (byte)1);
Array.setByte(d, 0, (byte)1);
You don't need to know whether the array you're dealing with is an int[]
or a long[]
to set a value to 5
, for example.
Edit I changed the example to hopefully demonstrate the fact that set...()
methods allow you to not necessarily know the primitive array's type statically.