Skip to content

Instantly share code, notes, and snippets.

@vojkny
Created February 19, 2012 16:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vojkny/1864457 to your computer and use it in GitHub Desktop.
Save vojkny/1864457 to your computer and use it in GitHub Desktop.
public class Fruit<T extends Fruit.Contents> {
@Setter @Getter
protected int id;
@Setter @Getter
protected Map<String, T> contents;
@Setter @Getter
protected String defaultKey;
protected class Contents {
@Setter @Getter
protected String name;
}
}
public class Apple extends Fruits<Apple.Contents> {
protected class Contents extends Fruit.Contents {
@Setter @Getter
protected String seed;
}
}
public class Lemon extends Fruits<Lemon.Contents> {
protected class Contents extends Fruit.Contents {
@Setter @Getter
protected int acidity;
}
}
Lemon lemon = ...;
lemon.getName(); // shorthand to call lemon.getContents().get(lemon.getDefaultKey).getName();
lemon.getAcidity();
Apple apple = ...;
apple.getName();
apple.getSeed();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment