[HD Pg 129, Sec. 5.1.6 - precedence]
Moderator: admin
-
- Posts: 221
- Joined: Mon Nov 26, 2018 2:43 pm
- Contact:
[HD Pg 129, Sec. 5.1.6 - precedence]
Looking at the table of precedence on page 130,
postfix expr++, expr-
unary ++expr, --expr, +expr, -expr, ~, !
How come in Java postfix has higher precedence than prefix?
Thanks
postfix expr++, expr-
unary ++expr, --expr, +expr, -expr, ~, !
How come in Java postfix has higher precedence than prefix?
Thanks
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 129, Sec. 5.1.6 - precedence]
Not sure I understand your question. It is the decision of the language designers.
If you like our products and services, please help us by posting your review here.
-
- Posts: 221
- Joined: Mon Nov 26, 2018 2:43 pm
- Contact:
Re: [HD Pg 129, Sec. 5.1.6 - precedence]
Oh I figured as much. I just was wondering if there was "as you always say about Java conventions" a logical reasoning behind their decision
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 129, Sec. 5.1.6 - precedence]
They most likely had a valid reason for it but I haven't seen it documented anywhere. I guess, they continued with the existing "convention" in this case.
If you like our products and services, please help us by posting your review here.
-
- Posts: 202
- Joined: Mon Apr 02, 2018 8:40 am
- Contact:
Re: [HD Pg 129, Sec. 5.1.6 - precedence]
This is the example you provided for explaining precedence:
The Cast operator is in the precedence table, but Parentheses are not in you precedence table nor the Parentheses are explained in the 5 chapter - Using Operators.
At least not in the tables in the chapter
Code: Select all
byte b = (byte)(i + 1);
At least not in the tables in the chapter
5.1.1 Overview of operators available in Java
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 129, Sec. 5.1.6 - precedence]
Because parentheses are not operators as such. They change the precedence of the components of an expression just like the mathematical expressions as mentioned at the start of the section. The book assumes you know BODMAS principle (from mathematics). For example, 2 + 6/2 is 5 but and (2+6)/2 is 4.
On page 131, the book says,
On page 131, the book says,
You can use parentheses to change how the terms of an expressions are grouped if the default grouping based on precedence and associativity is not what you want. The usage of parentheses for this purpose is fairly standard so I will not be discussing it any further.
If you like our products and services, please help us by posting your review here.
-
- Posts: 95
- Joined: Sat Dec 26, 2015 6:37 pm
- Contact:
Re: [HD Pg 129, Sec. 5.1.6 - precedence]
The parenthesis aren't matching.will be grouped as a = ( b = (c = 5) ;
-
- Site Admin
- Posts: 10062
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 129, Sec. 5.1.6 - precedence]
Correct. Added to errata.
thank you for your feedback!
thank you for your feedback!
If you like our products and services, please help us by posting your review here.
-
- Posts: 60
- Joined: Thu Apr 15, 2021 12:21 pm
- Contact:
Re: [HD Pg 129, Sec. 5.1.6 - precedence]
What could be a reason that (cast) has the (almost) highest precedence?
Who is online
Users browsing this forum: No registered users and 120 guests