While studying for my
SCJP 6 certification upgrade using the book "Sun Certified Programmer for
Java 6 Study Guide" by Kathy & Bert, I came across something that seems anomalous. I have described it in my blog entry
Primitive Assignments in Java. Here is what I find a little strange.
On page 192 of the book, it says that
is legal because the compiler automatically narrows the literal value to a
byte. However, on page 196, I found that
will
not compile. I checked this with the default compiler in NetBeans 6.7.1 and it is true. Why does the compiler not automatically narrow the
double literal to a
float here, just as it does for an
int literal to a
byte? Just wondering if there is any good reason for this, or is this just an unnoticed bug in the compiler?
Thanks...
- Ajoy