When assigments are happening right to left,why following doesn’t give compiler error?
String str = str = "";
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.
The behaviour is defined by the Java Lanaguage Specification #15.1 about the assignment operator. Namely (emphasis mine):
So the evaluation of the expression
str = str = "";is from right to left, but the left-hand operandString stris evaluated first and creates the variable.