Why don’t Java’s +=, -=, *=, /= compound assignment operators require casting long to int?

As always with these questions, the JLS holds the answer. In this case §15.26.2 Compound Assignment Operators. An extract: A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T)((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once. An example cited from §15.26.2 […] the following code is … Read more

What does the comma operator do?

Comma operator is applied and the value 5 is used to determine the conditional’s true/false. It will execute blah() and get something back (presumably), then the comma operator is employed and 5 will be the only thing that is used to determine the true/false value for the expression. Note that the , operator could be … Read more

What does =~ do in Perl? [closed]

=~ is the operator testing a regular expression match. The expression /9eaf/ is a regular expression (the slashes // are delimiters, the 9eaf is the actual regular expression). In words, the test is saying “If the variable $tag matches the regular expression /9eaf/ …” and this match occurs if the string stored in $tag contains … Read more

Under what circumstances are __rmul__ called?

When Python attempts to multiply two objects, it first tries to call the left object’s __mul__() method. If the left object doesn’t have a __mul__() method (or the method returns NotImplemented, indicating it doesn’t work with the right operand in question), then Python wants to know if the right object can do the multiplication. If … Read more