javaclass

tests/DispatchTest.java

139:9812fa1e4816
2005-01-21 Paul Boddie Worked on the documentation somewhat.
     1 public class DispatchTest {     2     public int a;     3     public float b;     4      5     public DispatchTest() {     6         this.a = 1;     7         this.b = 2;     8     }     9     10     public DispatchTest(int a) {    11         this.a = a;    12         this.b = 2;    13     }    14     15     public DispatchTest(float b) {    16         this.a = 1;    17         this.b = b;    18     }    19     20     public DispatchTest(int a, float b) {    21         this.a = a;    22         this.b = b;    23     }    24     25     public void set(int a) {    26         this.a = a;    27     }    28     29     public void set(float b) {    30         this.b = b;    31     }    32     33     // The ordering of the methods probably should not prevent the most specific    34     // method from being chosen, but this happens with a linear search of    35     // appropriate methods.    36     37     public int test(DispatchInterface obj) {    38         return obj.test();    39     }    40     41     public int test(DispatchClass1 obj) {    42         return obj.test() + 10;    43     }    44     45     public int testTest(DispatchInterface obj) {    46         return test(obj);    47     }    48 }    49     50 interface DispatchInterface {    51     public int test();    52 }    53     54 class DispatchClass1 implements DispatchInterface {    55     public int test() {    56         return 1;    57     }    58 }    59     60 class DispatchClass2 implements DispatchInterface {    61     public int test() {    62         return 2;    63     }    64 }