Created
May 18, 2012 16:55
-
-
Save krisskross/2726390 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 ProductCatalogue { | |
private Multimap<Class, ? extends Item> catalogue = ArrayListMultimap.create(); | |
public void add(Item item) { | |
catalogue.put(item.getClass(), item); | |
} | |
public <T extends Item> Collection<Item> list(Class<T> clazz) { | |
return catalogue.get(clazz); | |
} | |
} | |
ProductCatalogue catalogue = new ProductCatalogue(); | |
catalogue.add(new Book("1", "Book1")); | |
catalogue.add(new Movie("2", "Movie1")); | |
// only get books | |
System.out.println("Books " + catalogue.list(Book.class)); | |
// only get movies | |
System.out.println("Movies " + catalogue.list(Movie.class)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment