Why java.util.concurrent.atomic.AtomicBoolean is internally implemented with int? Why java.util.concurrent.atomic.AtomicBoolean is internally implemented with int? multithreading multithreading

Why java.util.concurrent.atomic.AtomicBoolean is internally implemented with int?


AFAIK, int is the smallest type CAS operations can be implemented across different machine types.

Note: as object allocations are 8 byte aligned, using a smaller type wouldn't save any memory.


This probably is to be able to base several of the Atomic classes on the same base (Unsafe), which uses integer and provides the compare and swap operation.

Concurrency in Practice provides a good explanation of the inner workings.