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

datatypes

 
Andre Fean
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Let's say we have following code:

Why is it working for int and long and why I have to do a typecast for short and byte?

Thanks & regards
Andre
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The results of arithmetic operations are automatically promoted to int in these examples so you have to cast them back to byte or short.
Bill
 
Andre Fean
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But that means it makes no sense to use for example a short in such a case.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic