In what way are these statements different?
- double dummy = 0;
- double dummy = 0.0;
- double dummy = 0.0d;
- double dummy = 0.0D;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Having tried a simple program (using both 0 and 100, to show the difference between “special” constants and general ones) the Sun Java 6 compiler will output the same bytecode for both 1 and 2 (cases 3 and 4 are identical to 2 as far as the compiler is concerned).
So for example:
compiles to:
However, I can’t see anything in the Java Language Specification guaranteeing this compile-time widening of constant expressions. There’s compile-time narrowing for cases like:
as specified in section 5.2, but that’s not quite the same thing.
Maybe someone with sharper eyes than me can find a guarantee there somewhere…