v79
04/12/2018, 6:40 PMAny?
object to an arbitrary KClass
. Here's what I would like to do:
fun Request.bind(modelClass: KClass<*>): Any? {
return WebForm(this,modelClass).get() as modelClass
}
I'd like to avoid having to type val person: Person = request.bind(Person::class) as Person
- that's a lot of references to Person
in a single line of code.diesieben07
04/14/2018, 7:53 PMinline fun <reified T> Request.bind(): T = WebForm(this, T::class).get() as T
diesieben07
04/14/2018, 7:55 PMKClass
you can do the following:
fun <T : Any> Request.bind(modelClass: KClass<T>): T = modelClass.cast(WebForm(this, modelClass).get())
v79
04/15/2018, 7:03 AM