• Post Reply Bookmark Topic Watch Topic
  • New Topic

Difference between additive & assignment operator  RSS feed

 
Sidharth Pallai
Ranch Hand
Posts: 137
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are there any difference between additive and assignment operator.

When i say and , are they result same values?
 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. They are equivalent.
 
Sidharth Pallai
Ranch Hand
Posts: 137
Hibernate Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Patricia Samuel wrote:Yes. They are equivalent.


Even i thought they are same, until i came across below
One provides implicit casting and the other not.

For Eg.

 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"x += y" is roughly the same as "x = (type)(x + y)" where "type" is one of byte, char, short, int, etc. This implicit cast is what causes "x += 1" to compile and "x = x + 1" to not compile - the result of any arithmetic operation is never byte, char or short.
 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
are they result same values?


And i guessed you are asking in the terms of result. There is no doubt left. Rob has cleared the thing now.
 
Campbell Ritchie
Marshal
Posts: 55770
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it carefully.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!