Hanumant Deshmukh (OCAJP Associate Java 8 Programmer Certification Fundamentals 1Z0-808) wrote:In other words, almost all of the operators in Java are defined to be left-associative. The only exceptions are the assignment operators (simple as well as compound) and the ternary operator.
Hey, this is a corner (edge of an edge) case, but as Charles pointed out that Hanumant Deshmukh mentioned somewhere else, all of the compound assignment operators are right-to-left as well.
jshell> x = 0
x ==> 0
jshell> y = 2
y ==> 2
jshell> z = 3
z ==> 3
jshell> a = x += y += z;
a ==> 5.0
x ==> 5
If it were true that simple = was the only right to left binary operator, x would be == 2 there, but literally all the compound assignment operators are right-to-left as well.
I feel like at some point I've seen this tested in someone's mock exam questions somewhere.
Hopefully not on real exam questions, but good to be prepared.
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop