Data Type Default Value (for fields)
byte 0
short 0
int 0
long 0L
float 0.0f
double 0.0d
char '\u0000'
String (or any object) null
boolean false
Therefore, you need to explicitly specify the number as a parameter for the primitive type you need
If you try to give
public static void main(String [] args) {
Test test = new Test();
test.m1(2L);
}
The output will be long
In the case of shortor byte(implicit is int), you need to cast to this type
public static void main(String [] args) {
Test test = new Test();
test.m1((short)2);
}
Reference: Primitive Data Types in Java
source
share