Skip to content

Instantly share code, notes, and snippets.

@adelatorrefoss
Last active August 29, 2015 14:03
Show Gist options
  • Select an option

  • Save adelatorrefoss/5e49a01f22766298e118 to your computer and use it in GitHub Desktop.

Select an option

Save adelatorrefoss/5e49a01f22766298e118 to your computer and use it in GitHub Desktop.
Repository implementation with generics
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