christopher
03/09/2018, 3:32 PMclass Bar<T> protected constructor(type: Class<T>) {
companion object {
inline operator fun <reified T> invoke(): Bar<T> {
return Bar(T::class.java)
}
}
}
val bar = Bar<String>()diesieben07
03/09/2018, 3:33 PMchristopher
03/09/2018, 3:34 PMBar<Type>() instead of Bar(Type::class.java). Not what you wanted?diesieben07
03/09/2018, 3:35 PMchristopher
03/09/2018, 3:35 PMchristopher
03/09/2018, 3:35 PMval bar at the end is just a demonstration.diesieben07
03/09/2018, 3:35 PMBar has the class parameter. The companion object should have it.christopher
03/09/2018, 3:35 PMchristopher
03/09/2018, 3:36 PMdiesieben07
03/09/2018, 3:36 PMchristopher
03/09/2018, 3:36 PMdiesieben07
03/09/2018, 3:36 PMdata class Person should have a companion object of type Model<Person>, and Model needs the Person class.diesieben07
03/09/2018, 3:37 PMModel then has methods like findAll, which would return all Person instances.christopher
03/09/2018, 3:38 PMdiesieben07
03/09/2018, 3:39 PMclass Model<reified T>diesieben07
03/09/2018, 3:40 PMchristopher
03/09/2018, 3:42 PMdiesieben07
03/09/2018, 3:43 PMby is the best I can do...christopher
03/09/2018, 3:43 PMchristopher
03/09/2018, 3:45 PMdiesieben07
03/09/2018, 3:45 PMchristopher
03/09/2018, 3:47 PM