I was trying to show how Java's evaluation of operands (always from left to right) corresponds to right associativity of assignments. Exceptions are just a method to stop execution at the right moment (debugging via exceptions
)
is equivalent to
First we evaluate 'a', then evaluate 'b', then evaluate 'c', then execute assignment b = c, then execute assignment a = (b = c).
Plus, this code sample shows that Java first computes index in array, then computes new value, then performs range check, then assigns new value. It gives us a way to stop execution during assignments.
First versions of my code sample had similar to the peek() method. I can't find good explanation why I switched to exceptions
Example for jshell nails my idea.