使用反射设置数组元素值
import java.lang.reflect.Array; import static java.lang.System.err; /* 来自 *n o w j a v a . c o m - 时代Java*/ public class ArrayTroubleAgain { public static void main(String... args) { Integer[] ary = new Integer[2]; try { Array.setInt(ary, 0, 1); // IllegalArgumentException // production code should handle these exceptions more gracefully } catch (IllegalArgumentException x) { err.format("Unable to box%n"); } catch (ArrayIndexOutOfBoundsException x) { x.printStackTrace(); } } /* *来 自 N o w J a v a . c o m - 时代Java */ }