Here is a snippet from definition of KProperty (yo...
# getting-started
e
Here is a snippet from definition of KProperty (you can crt-click to see it in IDE):
public interface KProperty<out R>
. It is defined with an
out
type parameter
R
, because it only only returns things of type
R
(it never receives them), so a call like
User::firstName.test(42)
infers the following call type
User::firstName.test<Any>(42)
, becuase
Any
is the nearest common supertype between
Int
and
String
and, because of an
out
parameter,
KMutableProperty<String>
is a subtype of
KMutableProperty<Any>
, so a method
test<Any>
, that is applicable to
KMutableProperty<Any>
is also Ok to use on a
KMutableProperty<String>
, which is a subtype of it.