The short answer: Java can automatically expand intand longup float, and doubles, but Java will choose an extension floatbecause it is smaller (in terms of memory) than double. You can invoke the method version of a doublemethod by explicitly passing an argument:
System.out.print(m((double)a1) + "," + m((double)b1));
:. Java ( ), , (, , ) . Java:
byte 1 byte
short 2 bytes
char 2 bytes
int 4 bytes
float 4 bytes
long 8 bytes
double 8 bytes
Java "" , Java . Java :
byte short, int, long, float doubleshort int, long, float doublechar int, long, float doubleint long, float doublelong float doublefloat to double
, :
- .
- ; .
int long float long double .
, Java int long , , long , int (. 2). Java int float, . .
public static void foo(float f) {
System.out.println(f);
}
public static void main(String[] args) {
int a = 123;
int b = 1234567890;
foo(a);
foo(b);
}
foo(float) "123.0", . int "123" float "123.0". "1.23456794E9", , 3. "1234567940" , , "1234567890".
, : , Java , , ( ), . , , , , , Java , .
int a long . Java m(float) m(double), , . int float double, float (4 ) , double (8 ), Java m(float). , long: float , , a long .