Java – coding guide for case of numeric text suffix

I did some Googling, but I couldn't find a solution to my problem

According to the double and float declarations, are there any Java coding guidelines? What is right?

Double d = 1.0d;

or

Double d = 1.0D;

(the same applies to float and long and their primitives.)

Compilation and both seem fine to me, but when I read these lines of code, I saw a difference in clarity The one with the capital D seems more likely to be mispronounced – > "d" can be read as around "0"

Any suggestions or ideas?

Solution

Start with the Java tutorials:

double d1 = 123.4;
// same value as d1,but in scientific notation
double d2 = 1.234e2;
float f1  = 123.4f;

This tells you:

>D and d have the same meaning – as you have observed > "by convention [D or D is omitted]" because they are the default values

"What is better" questions are off topic on stackoverflow because they can't have correct or incorrect answers, only opinions

But if you ask for a convention, I tend to follow what I found above - omitting the suffix

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>