1l for long, 1f for float, 1d for double, what about byte?
long l = 1l;
float f = 1f;
double d = 1d;
// byte b = 1?;
What's the equivalent for byte
? Does it exist?
It's a double literal.
According to the language specification, 0.0 is the same as 0.0d. JLS Section 3.10.2 describes this as follows: 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.
D stands for double. F for float. you can read up on the basic primitive types of java here.
It can represent a number as small as 4.9 x 10-324 and as big as 1.7 x 10308 in magnitude. It could be positive or negative. All real numbers are called double literals. A double literal may optionally end with d or D, for example, 1.27d.
No, there is no suffix you can append to a numeric literal to make it a byte
.
See 3.10 Literals in the Java Language Specification.
You need to cast to byte like this:
byte b = 1;
b = (byte) 5;
Since by default these numeric constant are treated as int in Java.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With