This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
How does this happen? boolean b1 = true; boolean b2 = false; boolean b3 = false; b3 &= b1 | b2; // prints false... b3 = b3 & b1 | b2; // prints true... Operator precedence is &, ^, | so why does the grouping change??? Is it because of the &= assignment operator? This is weird, but neat.
Is it because of the &= assignment operator? Yes. &= has the same precendence as =, which is much lower than the precedence for & or |. So, b3 &= b1 | b2 evaluates as b3 &= (b1 | b2) while b3 = b3 & b1 | b2 evaluates as b3 = ((b3 & b1) | b2)
Things like this make good questions for tests, only because they have right and wrong answers and are easy to grade. I'd like to see choices in tests like: A) This will print TRUE B) This will print FALSE C) Fire the programmer. In practice, I never trust the compiler, my memory or my reader's memory, and always use parens to express my intent.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com