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 Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Roundup #13 answer explanation not totally right

Serge Plourde
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#13 Assume: byte a=3; byte b=2; What is the result
of: byte c=a+b;
Answer: compiler error
The result of arithmetic is always at LEAST an int,
so the compiler will ask for an explicit cast:
byte c = (byte) a + b; even though a and b are bytes.

Writing <byte c = (byte) a + b;> still gives you the same error!
It should rather states:
byte c = (byte) (a+b);
which works. If the aim was to work with byte values.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic