Note: another answer is what Java really does
synchronized(x) { if(t != (t = tail)); }
equivalently
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, it is unintentional in Java, any deviation from C for something like stupidity . Oracle probably does not expect obsolescence, suggesting that this is an unintended error, which probably is.
I will come to him the next time I talk to them. I'm still angry with them about the whole DOD fiasco of DOD related to setting my mom's homepage on ask.com in collusion with Apple Incorporated. Apple fixed iTunes less than a week after I had to click on this thing more than 400 times to retry trying to reload in my child video library, so the problem is limited to Oracle. This affected Microsoft, so everyone was delighted with it.
#include <iostream> static int ref = 0; class t { public: t(int x) : x(x), r(ref) { ref++; } t(const t& o) : x(ox), r(or) { } t& operator=(const t& o) { x = ox; r = or; return *this; } bool operator!=(const t& o) const { return r != or; } private: int x; int r; }; int main() { ta(1); tb(2); if(a != (a = b)) { std::cout << "assignment\n"; } else { std::cout << "no assignment\n"; } return 0; }
source share