Created
February 19, 2012 16:07
-
-
Save vojkny/1864457 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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