package J20250802.demo03;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author WanJl
 * @version 1.0
 * @title MyAtomicInteger
 * @description
 * @create 2025/8/2
 */
public class MyAtomicInteger {
    public static void main(String[] args) {
        //创建一个无参的原子整型对象，默认的值为0
        AtomicInteger integer=new AtomicInteger();
        System.out.println(integer);
        //创建一个有参的原子整型对象，参数为666
        AtomicInteger integer2=new AtomicInteger(666);
        System.out.println(integer2);

        //获取值  get()
        System.out.println(integer2.get());

        //incrementAndGet()
        int incrementAndGet = integer.incrementAndGet();
        System.out.println(incrementAndGet);
        System.out.println(integer.get());

        //addAndGet(int delta)
        int addAndGet = integer2.addAndGet(75);
        System.out.println(addAndGet);
        System.out.println(integer2.get());

        //getAndSet(int value)
        int getAndSet = integer.getAndSet(70);
        System.out.println(getAndSet);
        System.out.println(integer.get());
    }
}
