• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Sybex CSG 17 - errata on page 68 - cast operator precedence

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cast operator has the highest precedence thus must be on the first row.

E.g.:

 
Marshal
Posts: 8954
646
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrius Orlonas wrote:Cast operator has the highest precedence thus must be on the first row.


Can you elaborate a bit, what do you mean by "must be on the first row"?

The fact that given code snippet outputs 10 and not 11, I don't think it has anything to do with Cast operator precedence.

Try to put ++doubleValue as opposed to doubleValue++ and see what you get then.

Or I misunderstood you?
 
Andrius Orlonas
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might be right. I used a faulty secondary source for the operator precedence table and could not find the evidence that the cast indeed happens first.
 
Sheriff
Posts: 28321
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you considering the possibility thatcould be equivalent to
? You'll find that isn't valid Java code.

Which implies that the cast can't possibly be evaluated before the ++ operator.
 
Andrius Orlonas
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, then there must be a mistake on the Enthuware OCP Java 11 book page 138 where the cast operator listed higher than the post increment op. That's where my confusion came from. I always considered Enthuware as an errata-free source.
 
Paul Clapham
Sheriff
Posts: 28321
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's always errors in published works. (We have a lot of posts on this site discussing those.) It's possible that this is one of them. I don't have the book so I can't comment about that, though.
 
Marshal
Posts: 79941
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrius Orlonas wrote:Cast operator has the highest precedence . . .

No, as people have already told you, it doesn't.
The whole idea of that sort of question is to remind you that although x++ has a higher precedence than casts, the post‑increment is hidden until the next time the variable is used. Also remember, if the value of x is outside the range -2147483648...2147483648exclusive, the increment will be annihilated by the cast. You will find all the gory details about casts in the Java Language Specification (=JLS).
 
Enthuware Software Support
Posts: 4883
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrius Orlonas wrote:Well, then there must be a mistake on the Enthuware OCP Java 11 book page 138 where the cast operator listed higher than the post increment op. That's where my confusion came from. I always considered Enthuware as an errata-free source.


Yes, that is a mistake. We apologize for the error. It has now been added to the errata. Will be fixed in the next iteration.
 
Evacuate the building! Here, take this tiny ad with you:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic