This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

+ operator

 
Ramya Iyer
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to understand a particular explanation of the + operator. Can some one provide example to throw light on this?

For a + expression with two operands of primitive numeric type, the result
has a value calculated by promoting the operands to the result type and then performing the addition using that type. This might result in overflow or loss of precision.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java, meaning the compiler and runtime system, will not (I think never) tell you that an overflow might occur.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ramya Iyer:
... Can some one provide example to throw light on this? ...

 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wonder if the question was about "promoting the operands to the result type". See if this example makes sense:

I think these show your statement was possibly misleading. The operands are not promoted to the declared type of the result variable but to the widest operand which becomes the actual result of the expression.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stan James:
I wonder if the question was about "promoting the operands to the result type"...

Good call. I missed that.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic