summaryrefslogtreecommitdiff
path: root/tests/047-returns/src/Main.java
blob: d53c4a7f35dccd6c26d0b2f9345e8ab571207684 (plain)
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
// Copyright 2007 The Android Open Source Project

/**
 * Return stuff.
 */
public class Main {
    public static void main(String[] args) {

        System.out.println("pick 1");
        pickOne(1).run();
        System.out.println(((CommonInterface)pickOne(1)).doStuff());

        System.out.println("pick 2");
        pickOne(2).run();
        System.out.println(((CommonInterface)pickOne(2)).doStuff());

        System.out.println("pick 3");
        pickOne(3).run();
    }

    public static Runnable pickOne(int which) {
        Runnable runme;

        if (which == 1)
            runme = new ClassOne();
        else if (which == 2)
            runme = new ClassTwo();
        else if (which == 3)
            runme = new ClassThree();
        else
            runme = null;

        return runme;
    }
}

class ClassOne implements CommonInterface, Runnable {
    public void run() {
        System.out.println("one running");
    }
    public int doStuff() {
        System.out.println("one");
        return 1;
    }
}

class ClassTwo implements CommonInterface, Runnable {
    public void run() {
        System.out.println("two running");
    }
    public int doStuff() {
        System.out.println("two");
        return 2;
    }
}

class ClassThree implements Runnable {
    public void run() {
        System.out.println("three running");
    }
}

interface CommonInterface {
    int doStuff();
}