• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

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: 8829
631
Mac OS X 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.
 
Marshal
Posts: 28003
94
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
Marshal
Posts: 28003
94
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: 78679
374
  • 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: 4770
52
  • 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.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic