CKTIS / Java
Multiplication assignment operator (*=)
The *= operator multiplies a variable's existing value by the right operand and stores the result back, converting it to the variable's type.
Version: Java SE 21; repository runtime, production runtime not attested
Syntax
variable *= expression;variable *= expression combines multiplication with assignment. Operands must support numeric multiplication; this operator does not repeat text.
If the left-hand side has type T, the compound assignment corresponds to variable = (T) (variable * (expression)), except that the left-hand side is evaluated only once. Its existing value is saved before evaluating the right-hand side.
The implicit result conversion can lose information: with short count = 5, count *= 2.5 stores 12. Writing count = count * 2.5 requires an explicit cast. Integer multiplication overflow does not throw an exception.
Examples
public class Main {
public static void main(String[] args) {
int total = 7;
total *= 3;
short count = 5;
count *= 2.5;
System.out.println(total);
System.out.println(count);
}
}Result
21 12
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.