Home | History | Annotate | Download | only in src
      1 // Copyright 2007 The Android Open Source Project
      2 
      3 /**
      4  * Return stuff.
      5  */
      6 public class Main {
      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 
     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 {
     38     public void run() {
     39         System.out.println("one running");
     40     }
     41     public int doStuff() {
     42         System.out.println("one");
     43         return 1;
     44     }
     45 }
     46 
     47 class ClassTwo implements CommonInterface, Runnable {
     48     public void run() {
     49         System.out.println("two running");
     50     }
     51     public int doStuff() {
     52         System.out.println("two");
     53         return 2;
     54     }
     55 }
     56 
     57 class ClassThree implements Runnable {
     58     public void run() {
     59         System.out.println("three running");
     60     }
     61 }
     62 
     63 interface CommonInterface {
     64     int doStuff();
     65 }
     66 
     67