• Post Reply Bookmark Topic Watch Topic
  • New Topic

Narrowing conversion  RSS feed

 
Piet Souris
Rancher
Posts: 1834
61
  • 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
Sheriff
Posts: 23026
120
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: 1834
61
  • 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   
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!