This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See 2> Now if we change the code as follows:
(true) ? b = b+1 : (b = 100) ;
Again this is wrong as values must be assigned to a variable.

3> Now Mr Anton Uwe has changed the code as follows
int vv;
vv=(true) ? (b = b + 1) : (b = 100);

The above code will still generate error.
The problem is in int he expression
b = b + 1;

Here b is byte , when b+1 is executed the result converted to int type and int value can not be assigned to a byte as there is a loss of precision so we need explicit type casting.

so the expression:
vv=(true) ? (b = (byte)(b + 1)) : (b = 100);
vv=(true) ? b = (byte)(b + 1) : (b = 100);
are correct now.
Kasak Tahilramani
Ranch Hand
Posts: 45
posted 11 years ago
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Sanjit-

It is Miss Kasak Tahilramani NOT Mr Kasak Tahilramani....

Thanks a lot for the explanation.
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!