爲何Java的+ =,-=,* =,/ =複合賦值運算符不須要強制轉換?

問題:

Until today, I thought that for example: 直到今天,我還覺得例如: ui

i += j;

Was just a shortcut for: 只是如下方面的捷徑: this

i = i + j;

But if we try this: 可是,若是咱們嘗試這樣作: spa

int i = 5;
long j = 8;

Then i = i + j; 那麼i = i + j; will not compile but i += j; 不會編譯,可是i += j; will compile fine. 會編譯的很好。 .net

Does it mean that in fact i += j; 這是否意味着實際上i += j; is a shortcut for something like this i = (type of i) (i + j) ? 是這樣的快捷方式i = (type of i) (i + j)嗎? code


解決方案:

參考一: https://stackoom.com/question/aY1r/爲何Java的-複合賦值運算符不須要強制轉換
參考二: https://oldbug.net/q/aY1r/Why-don-t-Java-s-compound-assignment-operators-require-casting
相關文章
相關標籤/搜索