Meaning of *= in Java

后端 未结 4 1744
孤城傲影
孤城傲影 2021-01-20 21:00

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

For example: density *= invertedRatio;

I am not familiar with the star-

4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-20 21:40

    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.

提交回复
热议问题