今天学习AtomicIntegerArray类,该类是JUC原子包中的数组类,通过单元测试代码把所有public api方法跑了一遍,大致了解了底层实现
package test.java.util.concurrent.atomic;
import java.util.concurrent.atomic.AtomicIntegerArray;
import java.util.function.IntBinaryOperator;
import java.util.function.IntUnaryOperator;
import org.junit.Test;
/**
* AtomicIntegerArray的测试类
*
* @author
* @date 2020-06-12 13:59:27
*/
public class AtomicIntegerArrayTest {
/**
* 通过size初始化AtomicIntegerArray数组类,其实就是将
* int[] array=new int[length];
* @throws
* @date 2020/6/16 23:46
*/
@Test
public void testConstruct0()throws Exception{
AtomicIntegerArray testObj=new AtomicIntegerArray(2);
System.out.println(testObj.toString());
}
/**
* 通过数组初始化AtomicIntegerArray数组类,其实就是将
* int[] array=intArr.clone();
* clone()方法是将intArr内容复制到一个新的相同大小的数组空间,
* 并将地址赋给array
* @throws
* @date 2020/6/16 23:46
*/
@Test
public void testConstruct1()throws Exception{
int[] intArr={1,2,3};
AtomicIntegerArray testObj=new AtomicIntegerArray(intArr);
System.out.println(testObj.toString());
}
/**
* array.length
* @throws
* @date 2020/6/16 23:46
*/
@Test
public void testLength(){
int[] intArr={1,2,3};
AtomicIntegerArray testObj=new AtomicIntegerArray(intArr);
System.out.println(testObj.length());
}
/**
* 获取数组下标的内容,需要检查是否越界
* @throws
* @date 2020/6/16 23:46
*/
@Test
public void testGet(){
int[] intArr={1,2,3};
AtomicIntegerArray testObj=new AtomicIntege