Years of Kotlin and Java and still can’t figure ou...
# random
m
Years of Kotlin and Java and still can’t figure out how to use
in
and
out
properly 😅 Passing a
Something<out Result, in Data>
to a function of
SomethingElse<out Result, in Data>
is impossible without casting and I’m pretty sure it’s wrong anyway. But I have no idea how to model something like that properly… In my case I have a
Visitor<out Result, in Data>
and want to pass it a
VisitCoordinator<out Result, in Data>
. Noooo legit way.
z
Can you give more details about the relationship between Visitor and VisitCoordinator? Does the latter implement/extend the former?
m
They just pass instances of
VisitCoordinator
to
Visitor
. I’ll follow up with the code once I’ve finished and pushed it 🙂
Definition: https://github.com/fluidsonic/fluid-graphql/blob/master/sources/common/language/visitors/Visit.kt#L15 Usage: https://github.com/fluidsonic/fluid-graphql/blob/master/sources/common/language/visitors/Visitor.kt#L6 Here’s the offender. Has been renamed by now. But I still have the projection issue. My visitor approach is still too messy in general. I guess I need a 4th refactoring 😄
z
You can annotate the
data
parameter to
__unsafeVisitChildren
with
@UnsafeVariance
to make the code compile, but you might get cast exceptions at runtime if a
Visitor.onNode
implementation passes an invalid type.
m
I forgot about
@UnsafeVariance
😄 So, I assume there’s no safe way to achieve that.
z
I don’t think so, with the API you have.