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

Why can't I sum two byte variables ?

 
Latif Ben
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Zeeshan Sheikh
Ranch Hand
Posts: 144
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Binary operation (+) in java would return integer which is why there is loss of precision. You have to explicitly cast expression back to byte.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, to keep your code readable, declare only one variable per line:



Also, don't increase your indent level unless you increase your block depth

 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zeeshan Sheikh wrote:Binary operation (+) in java would return integer which is why there is loss of precision. You have to explicitly cast expression back to byte.


Note, however, that the += operator does the cast for you, so



should work.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic