Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

left hand side in Java syntax

Tags:

java

I am preparing Java grammar for my parser generator. Noticed that statements like "(x) = 5 ;" where x is an "int" compile and execute correctly, but cannot see that Java Language Specification allows "(x)" as left hand side. Am I missing something?

like image 449
Redz Avatar asked Jul 18 '19 09:07

Redz


People also ask

What does :: mean in Java?

The double colon (::) operator, also known as method reference operator in Java, is used to call a method by referring to it with the help of its class directly. They behave exactly as the lambda expressions.

What is the left hand side of an assignment must be a variable?

In an assignment statement, the value of the right-hand side is assigned to the left-hand side. The left-hand side must be a variable, property, or indexer. To fix this error, make sure that all operators are on the right-hand side and that the left-hand side is a variable, property, or indexer.

Can you use or in Java?

We use the symbol || to denote the OR operator. This operator will only return false when both conditions are false. This means that if both conditions are true, we would get true returned, and if one of both conditions is true, we would also get a value of true returned to us. Let's go over a few examples.


1 Answers

The following part of the JLS should be the relevant one :

15.8.5. Parenthesized Expressions

If the contained expression denotes a variable then the parenthesized expression also denotes that variable.

Which means (x) is equivalent to x, x being an expression by itself.

like image 166
Arnaud Avatar answered Oct 03 '22 00:10

Arnaud