44 lines
1.0 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// housekeeping/Demotion.java
// (c)2021 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -08:00
// We make no guarantees that this code is fit for any purpose.
2016-09-23 13:23:35 -06:00
// Visit http://OnJava8.com for more book information.
2016-01-25 18:05:55 -08:00
// Demotion of primitives
2015-06-15 17:47:35 -07:00
public class Demotion {
void f1(double x) {
System.out.println("f1(double)");
}
2015-11-03 12:00:44 -08:00
void f2(float x) { System.out.println("f2(float)"); }
void f3(long x) { System.out.println("f3(long)"); }
void f4(int x) { System.out.println("f4(int)"); }
void f5(short x) { System.out.println("f5(short)"); }
void f6(byte x) { System.out.println("f6(byte)"); }
void f7(char x) { System.out.println("f7(char)"); }
2015-06-15 17:47:35 -07:00
void testDouble() {
double x = 0;
2015-11-03 12:00:44 -08:00
System.out.println("double argument:");
2015-12-18 11:28:19 -08:00
f1(x);
f2((float)x);
f3((long)x);
f4((int)x);
f5((short)x);
f6((byte)x);
f7((char)x);
2015-06-15 17:47:35 -07:00
}
public static void main(String[] args) {
Demotion p = new Demotion();
p.testDouble();
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2015-06-15 17:47:35 -07:00
double argument:
f1(double)
f2(float)
f3(long)
f4(int)
f5(short)
f6(byte)
f7(char)
2015-09-07 11:44:36 -06:00
*/