1 class AtomicIntegerArrayTest{
2     static int[] value = new int[]{1,2};
3     static AtomicIntegerArray ai = new AtomicIntegerArray(value);
4     public static void main(String[] args){
5         ai.getAndSet(0,3);
6         System.out.println(ai.get(0));
7         System.out.println(value[0]);
8     }
9 }

输出:

3
1

需要注意的是,数组value通过构造方法传递进去,然后AtomicIntegerArray会将当前数组赋值一份,所以当AtomicIntegerArray对内部的数组元素进行修改时,不会影响传入的数组

posted on 2017-12-13 15:56  飞奔的菜鸟  阅读(118)  评论(0编辑  收藏  举报