Constant expressions that fit in the type of the variable ( byte in our case) will be automatically converted by the compiler.Ī narrowing primitive conversion may be used if the type of the variable is byte, short, or char, and the value of the constant expression is representable in the type of the variable. There are some special language rules for so called assignment contexts. (If it wasn’t byte b = Byte.MAX_VALUE + 0 would not have compiled!)īyte b = a + 1 // can't convert from int to byte Why is a byte not allowed to overflow like an int? Byte.MAX_VALUE happens to be a constant variable.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |