A test case for static inner class
authorjzhou <jzhou>
Thu, 2 Dec 2010 18:43:50 +0000 (18:43 +0000)
committerjzhou <jzhou>
Thu, 2 Dec 2010 18:43:50 +0000 (18:43 +0000)
Robust/src/Tests/StaticInnerClassTest.java [new file with mode: 0644]

diff --git a/Robust/src/Tests/StaticInnerClassTest.java b/Robust/src/Tests/StaticInnerClassTest.java
new file mode 100644 (file)
index 0000000..a7c555b
--- /dev/null
@@ -0,0 +1,55 @@
+class Contents {
+  int value();
+}
+
+
+public interface Destination {
+  String readLabel();
+} ///:~
+
+public class StaticInnerClassTest {
+  public StaticInnerClassTest(){}
+  
+  private static class ParcelContents implements Contents {
+    private int i;
+    
+    public ParcelContents() {i = 11;}
+    public int value() { return i; }
+  }
+  
+  protected static class ParcelDestination
+  implements Destination {
+    private String label;
+    private ParcelDestination(String whereTo) {
+      label = whereTo;
+    }
+    public String readLabel() { return label; }
+    // Nested classes can contain other static elements:
+    public static void f() {}
+    static int x;
+    static {
+      x = 10;
+    }
+    static class AnotherLevel {
+      public static void f() {}
+      static int x;
+      static {
+        x = 10;
+      }
+    }
+  }
+    
+  public static Destination destination(String s) {
+    return new ParcelDestination(s);
+  }
+  
+  public static Contents contents() {
+    return new ParcelContents();
+  }
+  
+  public static void main(String[] args) {
+    Contents c = contents();
+    Destination d = destination("Tasmania");
+    System.out.println(d.readLabel());
+  }
+} ///:~