2015-09-07 11:44:36 -06:00
|
|
|
// innerclasses/Parcel11.java
|
2021-01-31 15:42:31 -07:00
|
|
|
// (c)2021 MindView LLC: see Copyright.txt
|
2015-11-15 15:51:35 -08:00
|
|
|
// We make no guarantees that this code is fit for any purpose.
|
2016-09-23 13:23:35 -06:00
|
|
|
// Visit http://OnJava8.com for more book information.
|
2016-01-25 18:05:55 -08:00
|
|
|
// Nested classes (static inner classes)
|
2015-06-15 17:47:35 -07:00
|
|
|
|
|
|
|
public class Parcel11 {
|
2016-01-25 18:05:55 -08:00
|
|
|
private static class
|
|
|
|
ParcelContents implements Contents {
|
2015-06-15 17:47:35 -07:00
|
|
|
private int i = 11;
|
2021-01-31 15:42:31 -07:00
|
|
|
@Override public int value() { return i; }
|
2015-06-15 17:47:35 -07:00
|
|
|
}
|
2016-11-21 12:37:57 -08:00
|
|
|
protected static final class ParcelDestination
|
2015-06-15 17:47:35 -07:00
|
|
|
implements Destination {
|
|
|
|
private String label;
|
|
|
|
private ParcelDestination(String whereTo) {
|
|
|
|
label = whereTo;
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public String readLabel() { return label; }
|
|
|
|
// Nested classes can contain other static elements:
|
|
|
|
public static void f() {}
|
|
|
|
static int x = 10;
|
|
|
|
static class AnotherLevel {
|
|
|
|
public static void f() {}
|
|
|
|
static int 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");
|
|
|
|
}
|
2015-09-07 11:44:36 -06:00
|
|
|
}
|