Page 1 of 1

[HD Pg 0, Sec. 3.3.3 - primitive-assignment]

Posted: Wed Feb 01, 2023 9:03 am
by BSilviu
Hi guys,

Stupid question maybe, but I'm feeling a little bit puzzled:

final int i = 10;
byte b = i; compiles fine because i is a compile time constant.

But, for instance, if I write something like:

final long k = 10;
int j = k; it doesn't compile anymore.

What am I missing? I expect, since k is a compile time constant, to compile just fine...

Re: [HD Pg 0, Sec. 3.3.3 - primitive-assignment]

Posted: Wed Feb 01, 2023 9:46 am
by admin
Yes, ideally, since k is a compile time constant and its value fits an int, this assignment should be allowed. However, the Java Language specification allows implicit narrowing only for byte, char, short, and int.
As per section 5.2 of JLS 11:
In addition, if the expression is a constant expression (ยง15.28) of type byte, short, char, or int:
A narrowing primitive conversion may be used if the variable is of type byte, short, or char, and the value of the constant expression is representable in the type of the variable.
Looks like the book missed mentioning this point.

Re: [HD Pg 0, Sec. 3.3.3 - primitive-assignment]

Posted: Wed Feb 01, 2023 10:02 am
by BSilviu
Cool! Thanks for the clarification. I also ordered the printed version of the book and also the mockup exams from Enthuware.
Reading this book, and taking the mockup exams, should be enough in order to get the certification for 1Z0-808? :cheers:

Re: [HD Pg 0, Sec. 3.3.3 - primitive-assignment]

Posted: Wed Feb 01, 2023 10:08 am
by admin
Yes, that should be enough.
Please see this to take full advantage of going through the mock exams: https://enthuware.com/help/faq/112-faq/ ... -enthuware

Re: [HD Pg 0, Sec. 3.3.3 - primitive-assignment]

Posted: Wed Feb 01, 2023 10:56 am
by BSilviu
One more thing. I've ordered my printed version from amazon.de.
I've read that the book is printed on demand, so I should get the latest version. Can you confirm this? What's the latest version of the printed book?

Thanks.

Re: [HD Pg 0, Sec. 3.3.3 - primitive-assignment]

Posted: Wed Feb 01, 2023 11:30 am
by admin
Yes, you should get the latest version as mentioned on Amazon (Last Updated: 5th Jun 2020 Build 31).