• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2007 The Android Open Source Project
2 
3 /**
4  * Return stuff.
5  */
6 public class Main {
main(String[] args)7     public static void main(String[] args) {
8 
9         System.out.println("pick 1");
10         pickOne(1).run();
11         System.out.println(((CommonInterface)pickOne(1)).doStuff());
12 
13         System.out.println("pick 2");
14         pickOne(2).run();
15         System.out.println(((CommonInterface)pickOne(2)).doStuff());
16 
17         System.out.println("pick 3");
18         pickOne(3).run();
19     }
20 
pickOne(int which)21     public static Runnable pickOne(int which) {
22         Runnable runme;
23 
24         if (which == 1)
25             runme = new ClassOne();
26         else if (which == 2)
27             runme = new ClassTwo();
28         else if (which == 3)
29             runme = new ClassThree();
30         else
31             runme = null;
32 
33         return runme;
34     }
35 }
36 
37 class ClassOne implements CommonInterface, Runnable {
run()38     public void run() {
39         System.out.println("one running");
40     }
doStuff()41     public int doStuff() {
42         System.out.println("one");
43         return 1;
44     }
45 }
46 
47 class ClassTwo implements CommonInterface, Runnable {
run()48     public void run() {
49         System.out.println("two running");
50     }
doStuff()51     public int doStuff() {
52         System.out.println("two");
53         return 2;
54     }
55 }
56 
57 class ClassThree implements Runnable {
run()58     public void run() {
59         System.out.println("three running");
60     }
61 }
62 
63 interface CommonInterface {
doStuff()64     int doStuff();
65 }
66