andre.artus
01/16/2017, 5:13 AM//Generic
interface Model<T> {
fun <K : Comparable<K>> find(key: K?): T?
}
or
interface Model<T> {
fun find(key: Any?): T?
}
Specific: the key for a Thing
will always be a String?
, but another specific case could be an Int?
interface ThingModel : Model<Thing> {
fun find(key: String?): Thing?
}
interface ThangModel : Model<Thang> {
fun find(key: Int?): Thang?
}
I intend the implementations to return the result from memory when available, and to query a db if not, otherwise I would just use the built in find(predicate: (T) -> Boolean)
At the moment if I just do implementations of the generic interfaces I can compile the following:
val m = ModelImpl()
m.find(0)
m.find("")
class ModelImpl : ThingModel
I want this to be an error, that is I want implementations to be constrained to one type of, for instance, either String or Int.