`x` is what I need to find
# announcements
e
x
is what I need to find
s
I’m a little lost then - do you just not know what
x
is, or is
x
determined at runtime or something similarly funky?
what’s the full signature of
Structure.convertCamera
?
e
it's getting complex, let me write it down clearly on SO
s
kk
s
ohhhhhh, this makes much more sense
e
glad to read that
s
er, not to get your hopes up - what you’re doing is still kinda wonky, not gonna lie
but this is much easier to reason about
e
I know, but since I'm porting some c++ code I'd like to stick to original structure if possible
s
I feel you - I’ve worked on some legacy conversion before as well, but at some point you gotta avoid trying to write C++ in Kotlin
e
so, you didnt make it either?
s
er, not sure what you mean
e
I mean regarding my question
you cant see a solution?
s
ah, I’m still thinking on it
e
(other than change design)
s
I think there should be a solution for this particular issue, and I think I can coerce the type system into cooperating, but I also wanted to give the disclaimer that you maybe writing less maintainable Kotlin as a result
okay, so, after massaging the compiler a bit, this is about as succinct as I could get the type to be
Copy code
MutableMap<String, Pair<() -> Camera, Structure.(KMutableProperty0<Camera>) -> Unit>>
e
😄
Camera
works, but I'd like to get a generic
ElemBase
s
if
Structure
is too specific, you might be able to use a superclass or interface instead, but what you can’t avoid is including a receiver type there since
Structure::convertCamera
is a member function and implicitly always includes a reference to the class it belongs to
ah, okay
I think you can swap in ElemBase safely
wait, actually, I don’t think you can
if
convertCamera
explicitly takes in
KMutableProperty0<Camera>
, then I don’t think you can pass in a supertype
e
I updated the question
I assigned the pair to a
var
and looked at its type
I have
KFunction0
and
KFunction2
that I do not have available... wtf?
I only have
KFunction
..
s
blinks
what
KFunction...
are all in
kotlin.reflect
maybe try explicitly importing them? 🤷
e
s
I’d try
import kotlin.reflect.KFunction0
and
import kotlin.reflect.KFunction2
or just using
() -> ElemBase
and
(Structure, KMutableProperty0<Camera>) -> Unit
the second one should be identical to
Structure.(KMutableProperty0<Camera>) -> Unit
e
super interesting, if I import it manually seems working
s
intellij weirdness if I had to guess
e
but if I click on the import, it cannot resolves it
some runtime only stuff?
s
wow, that’s annoying lmao
maybe you need to refresh the kotlin plugin? or tell your build doober to pull down
kotlin-stdlib-*
again?
e
no idea
anyway, Q updated again
s
do you have
()
at the end of your type annotation?
e
yes
s
I don’t think you need that there
e
wait wait, missing a
>
val converters = mutableMapOf<String, Pair<KFunction0<Camera>, KFunction2<Structure, KMutableProperty0<Camera>, Unit>>>()
did it
also the corresponding
ElemBase
version
thanks dear, it was indeed a typo
wait,
ElemBase
turned red..
uff