javaclass

Annotated tests/DispatchTest.java

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