https://kotlinlang.org logo
Title
h

Hullaballoonatic

06/13/2019, 9:38 PM
fun <F: Foo> foo1(fooRef: KProperty1<Bar, Foo>) = ...

fun <F: Foo> foo2(foo: Foo) = foo1(WHAT GOES HERE?)
Is there a simple way to do this?
Bar::(something with foo)
?
k

karelpeeters

06/13/2019, 10:23 PM
foo1
takes a property of
Bar
with type
Foo
, and all you've got is an instance or
Foo
. How could that possibly converted to the latter?
h

Hullaballoonatic

06/13/2019, 10:27 PM
so let's say
fooRef: KProperty1<Bar, String>
, e.g.
Bar::name
. How could you engineer
KProperty1<Bar, String>
from
name
?
k

karelpeeters

06/13/2019, 10:31 PM
Do you happen to be confused about how variables work? If I have a class
class Bar(val name: String)
and then I do
foo2(bar.name)
there's no connection to
bar
anymore,
bar.name
is just an ordinary
String
instance out there with everything else
You can't engineer a property from a random instance, it may not even be a property,
foo("test")
, it may be a "property" of multiple classes, it may be in a list somewhere, ...
h

Hullaballoonatic

06/13/2019, 10:32 PM
Yeah, so you can provide the
Bar
part yourself again.
alright. i'll try to think of a different solution
k

karelpeeters

06/13/2019, 10:33 PM
I don't get what you want to happen.
👆 2
1