homchom
09/18/2022, 9:43 PMPair<List<String>, String> is just for testing purposes and is not final.)ephemient
09/18/2022, 10:15 PM(Pair<List<String>, String>, Boolean) -> Boolean
should translate to the Java type
Function2<? extends Pair<? extends List<? extends String>, ? extends String>, ? extends Boolean, ? super Boolean>homchom
09/19/2022, 5:38 PM? super Pair and ? super Boolean, since Function2 has variance <in, in, out>? Either way, though, I'm passing in the exact types required, so variance shouldn't even matter. That's why I'm confused.ephemient
09/19/2022, 9:52 PMephemient
09/19/2022, 9:54 PMList<String> is not a subtype of List<? extends String> etc.homchom
09/19/2022, 10:00 PMhomchom
09/20/2022, 12:07 AMList<Pair<String, String>> works fine, but Pair<List<String>, String> does not. Furthermore, if I take List out of the equation entirely with Pair<Pair<String, String>, String> everything works. The issue happens if I replace List with Lazy (Lazy was my original intended type), so it appears to be an issue with invariant types.homchom
09/20/2022, 12:23 AMrun function is defined in Java code, so I'm actually trying to go backward from ? extends T back to just T, which is not safe. In other words, the variance information is lost along the way.
Furthermore, while it is true that List<String> is a subtype of List<? extends String> is, it is of course not a supertype, which is required by the Kotlin function, so when the variance info is lost in the Java code, problems ensue.
Moral of the story is variance is still extremely confusing.
@ephemient thanks for your help!