1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
// JSwat test for finding methods in classes.
// $Id: Methods.java 928 2003-04-10 04:31:00Z nfiedler $
public class Methods {
public void print(Byte b) {
System.out.println("B = " + b);
}
public void print(short s) {
System.out.println("s = " + s);
}
public void print(Short s) {
System.out.println("S = " + s);
}
public void print(int i) {
System.out.println("i = " + i);
}
public void print(Integer i) {
System.out.println("I = " + i);
}
public void print(long l) {
System.out.println("l = " + l);
}
public void print(Long l) {
System.out.println("L = " + l);
}
public void print(Object o) {
System.out.println("o = " + o);
}
public void print(String s) {
System.out.println("z = " + s);
}
public String toString() {
return "me";
}
public static void main(String[] args) {
Methods me = new Methods();
// Note how this calls the short method, rather than Byte.
me.print((byte) 5);
// Integer method is the default.
me.print(10);
// Must typecast to get non-integer method.
me.print((short) 20);
// Longs can be specified with the L suffix.
me.print(30L);
// Again, have to typecast to get non-integer.
me.print(new Short((short) 5));
me.print(me);
Methods2 me2 = new Methods2();
me2.print(40);
me2.print(50L);
// Have to typecast null to a specific type.
me2.print((String) null);
me2.print(new Integer(101));
me2.print("abc");
me2.print(me2);
}
}
|