File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Programmer Certification (SCJP/OCPJP)
why this flaw in typecasting
Joined: Jun 07, 2006
Jun 09, 2006 10:55:00
byte b=127 is compiled fine though literal 127 is integer but no type cast required.
float f=32.3 is not compiled fine just because literal 32.3 is implicitly double and type cast required.
Joined: Dec 09, 2003
Jun 09, 2006 11:08:00
for byte, short, char, int types, you don't need to cast it explicitly iff the right value is assignable to the left one. But this rule does not apply to the float and double.
Let it snow~
Joined: Feb 02, 2006
Jun 09, 2006 14:10:00
A floating-point literal is of type float if it is suffixed with an ASCII letter F or f; otherwise its type is double and it can optionally be suffixed with an ASCII letter D or d.
I agree. Here's the link:
subject: why this flaw in typecasting
Boxing of literals (was Short s = 7;)
What is the type of 1/3?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013