Are a += 10 and a = a + 10 both the same, or is there some difference between them? I got this question while studying assignments in Java.
Are a += 10 and a = a + 10 both the same, or
Share
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.
As you’ve now mentioned casting… there is a difference in this case:
From the Java Language Specification section 15.26.2:
Interestingly, the example they give in the spec:
is valid in Java, but not in C#… basically in C# the compiler performs special-casing of += and -= to ensure that the expression is either of the target type or is a literal within the target type’s range.