• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Narrowing conversion

 
Piet Souris
Rancher
Posts: 1516
32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never thought I would ever ask a question like this, but this OCAJP 8 drives me mad, from time to time. Here goes:

According to the JLS, 5.2:

A narrowing primitive conversion may be used if the type of the variable is byte, short, or char, and the value of the constant expression is representable in the type of the variable.

Now, given that, why do I get the following results. The book I have seems to take this for granted (one of the well known OCAJP books)

Thanks!

Edit: good heavens. The line just before the quoted line is:

In addition, if the expression is a constant expression (ยง15.28) of type byte, short, char, or int:

Missed that... sorry about it.
 
Henry Wong
author
Marshal
Pie
Posts: 22089
88
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I actually clicked reply -- but then noticed that you had edited the question. Regardless, have a cow for figuring it out on your own...

Henry
 
Piet Souris
Rancher
Posts: 1516
32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Henry.

All I can say: my admiration for all those who passed this exam is increasing and increasing   
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic