Note: the other answer is what Java is actually doing
synchronized(x) {
if(t != (t = tail));
}
is equivalent to
synchronized(x) {
t = tail;
if(t != t) {
// ...
}
}
basically, a reference to what is assigned is returned by the ( ) operator
public class Test {
public static void main(String[] args) {
Integer a = 1;
Integer b = 2;
if(a != (b = a)) {
System.out.println("however, there is an issue with a != (a = b), Java bug");
} else {
System.out.println("assignment first, obvious by inspection");
}
}
}
However, the same code works in C. If I had to guess, this is unintentional in Java, any departure from C on something like this is folly. Oracle probably isn't looking forward to deprecating it, assuming it is a unintentional bug, which it probably is.
I'll get to it the next time I talk to them. I'm still mad at them regarding that whole Abode fiasco at the DOD related to setting my mom's homepage to ask.com in collusion with Apple Incorporated. Apple fixed iTunes in less than a week after I had to click the thing over 400 times in order to retry after re-download failures of my daughter's video library though, so the issue is limited to Oracle. It affected Microsoft as well so everyone was mad about it.
#include <iostream>
static int ref = 0;
class t {
public:
t(int x) : x(x), r(ref) { ref++; }
t(const t& o) : x(o.x), r(o.r) { }
t& operator=(const t& o) { x = o.x; r = o.r; return *this; }
bool operator!=(const t& o) const { return r != o.r; }
private:
int x;
int r;
};
int main() {
t a(1);
t b(2);
if(a != (a = b)) {
std::cout << "assignment\n";
} else {
std::cout << "no assignment\n";
}
return 0;
}