I have a class like follow:
class Weekend<T : Any> {
fun <R> equal(property: KProperty1<T, R>, value: R?) {
...
return this
}
}
and use the class like follow:
Weekend<User>().equal(User::name, "username")
in this case, User.name
is a string property, and "username" is also a string. But if I write the code like Weekend<User>().equal(User::name, 22)
, kotlin will not give errors, because string
and Int
has the same parent Compareble
.
Is there any way to tell kotlin the second param value
must be a string
here? (I know Weekend<User>().equal<String>(User::name, 22)
will work, but I want a simple way to do this.)