I just learned about the AtomicInteger a few days ago. Didn't realize it existed before. I haven't tried it yet. I used to simply write my own MutableInteger class. Integer has no "set" method. AtomicInteger does, so I imagine that it can now replace my MutableInteger class. My question is why do we even need AtomicInteger. Why didn't they just allow Integers to be mutable? Clearly this was on purpose and the designers seem (at least to me) hell bent on making a regular old "swap" function impossible in order to discourage it...
int swap(int& a, int& b)
{
int temp = a;
a = b;
b = temp
}
I've long tried to find workarounds, but it seems to me that if you were supposed to do it, they wouldn't have made it so difficult, so I'm trying to figure out what the "correct" thinking process is. Why aren't Integers mutable and how does one write the good old "swap" method?