Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Arithmetic Compound Assignment Operators..

 
Phillipe Rodrigues
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why i get output for the below program?

---------- Run ----------
Hello World!
Normal Termination
Output completed (0 sec consumed).



 
Campbell Ritchie
Sheriff
Pie
Posts: 50246
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To the Batmobile!

Oh no, that should be Java Language Specification, or anywhere where you can read that the compound operators can return their original type rather than going to int.

It is quite complicated; they can create an int and then return it to their original type, so your example will compile and run happily, but you can get some unexpected results if you use types "narrower" than int (short, byte, char). It is described lot better in the Java Language Specification page I showed you. "Complete abruptly" means to suffer an exception at runtime.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic