[英]How do you call this kind of assignment : float aFloat = 4.f;
I am trying to figure how do you call this, I thought of "implicit datatypes" but it seems this really isn't what I imagined.我想知道你怎么称呼它,我想到了“隐式数据类型”,但似乎这真的不是我想象的那样。
I also want to know all of the possibilities in Java, like I know you can do it for other numerical values, like bytes, integers, longs, etc. I'd search by myself but I still don't know how to define this sort of numerical variable assignment, or how to name it.我也想知道 Java 中的所有可能性,就像我知道你可以为其他数值做它,比如字节、整数、长整数等。我自己搜索但我仍然不知道如何定义这个一种数值变量赋值,或者如何命名它。
I was just curious about this but I still really want to know!我只是对此感到好奇,但我仍然很想知道!
Thanks in advance.提前致谢。
In your example, it's really not "implicit".在您的示例中,它确实不是“隐式”的。 Quite the reverse.恰恰相反。
Here's more on primitive types and their notations (examples pasted below) from the official Java Tutorials , and some tricks you need to know about floats .以下是官方Java 教程中有关原始类型及其符号(下面粘贴的示例)的更多信息,以及您需要了解的有关浮点数的一些技巧。
You may also want to learn more about conversions, promotions and narrow-casting .您可能还想了解更多关于转化、促销和窄选的信息。
int decVal = 26; // The number 26, in decimal
int octVal = 032; // The number 26, in octal
int hexVal = 0x1a; // The number 26, in hexadecimal
int binVal = 0b11010; // The number 26, in binary
double d1 = 123.4;
double d2 = 1.234e2; // same value as d1, but in scientific notation
float f1 = 123.4f;
using underscores (since Java 7)使用下划线(自 Java 7 起)
long creditCardNumber = 1234_5678_9012_3456L;
long socialSecurityNumber = 999_99_9999L;
float pi = 3.14_15F;
long hexBytes = 0xFF_EC_DE_5E;
long hexWords = 0xCAFE_BABE;
long maxLong = 0x7fff_ffff_ffff_ffffL;
byte nybbles = 0b0010_0101;
long bytes = 0b11010010_01101001_10010100_10010010;
I agree with haylem, it is not implicit.我同意 haylem,这不是隐含的。
You asked for other numerical types examples:您要求提供其他数字类型示例:
Integer types: Integer 类型:
073 (leading zero, octal)
123l (long)
0xFF (hex)
Floating point:浮点:
1.1E-3 (double)
1e10f (float)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.