Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meaning of *= in Java

Tags:

java

notation

I see an unfamiliar notation in the Android source code: *=

For example: density *= invertedRatio;

I am not familiar with the star-equals notation. Can somebody explain it?

like image 210
IgorGanapolsky Avatar asked Nov 27 '22 22:11

IgorGanapolsky


2 Answers

In Java, the *= is called a multiplication compound assignment operator.

It's a shortcut for

density = density * invertedRatio;

Same abbreviations are possible e.g. for:

String x = "hello "; x += "world" // results in "hello world"
int y = 100; y -= 42; // results in y == 58

and so on.

like image 125
Dominik Sandjaja Avatar answered Feb 13 '23 19:02

Dominik Sandjaja


density *= invertedRatio; is a shortened version of density = density * invertedRatio;

This notation comes from C.

like image 45
AlexR Avatar answered Feb 13 '23 18:02

AlexR