Why is
byte someVar;
someVar -= 3;
valid but
byte someVar;
someVar = someVar - 3;
isnt?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Surprisingly, when you perform operations on bytes the computations will be done using
intvalues, with the bytes implicitly cast to(int)first. This is true forshorts as well, and similarlyfloats are up-converted todoublewhen doing floating-point arithmetic.The second snippet is equivalent to:
Because of this you must cast the result back to
(byte)to get the compiler to accept the assignment.