Last active
August 29, 2015 14:03
-
-
Save adelatorrefoss/5e49a01f22766298e118 to your computer and use it in GitHub Desktop.
Repository implementation with generics
This file contains hidden or 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
| interface Repository<T> { | |
| T save(T t) | |
| } | |
| interface IntegerRepository { | |
| Integer findByIntegers(String name) | |
| } | |
| abstract class InMemoryRepository<A> implements Repository<A> { | |
| A save(A a) { | |
| println a.getClass() | |
| } | |
| } | |
| class IntegerInMemoryRepository extends InMemoryRepository<Integer> implements IntegerRepository { | |
| Integer findByIntegers(String name) { | |
| return 10 | |
| } | |
| } | |
| class StringInMemoryRepository extends InMemoryRepository<String>{} | |
| new EventInMemoryRepository().save(3) | |
| new StringInMemoryRepository().save(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment