So uh I have some old code that I’m trying to upda...
# announcements
r
So uh I have some old code that I’m trying to update to Kotlin 1.4 and it stopped working. Here is a reproducer https://pl.kotl.in/GGe3tNnwm (try changing the Kotlin version from <1.4 to 1.4+ to see different results) I fear it was actually using a bug that was fixed. Any idea of how I should transform this code to achieve the same behavior as before?
n
define "stopped working"
b
Copy code
interface A
interface B
class C : A, B

class Handler<T>

open class Handlers<T>(val list: List<Handler<in T>>)

class CHandlers: Handlers<C>(listOf<Handler<in C>>(Handler<A>(), Handler<B>()))

fun main(args: Array<String>) {
    CHandlers()
    println("Hello world")
}
That seems to work
r
@nanodeath can’t you click on a link?
n
ah...it's executable. sorry I've never used this before.
Ben's suggestion does seem to work though
r
Yes it looks like it works, though in my case I actually have lists of lists and my classes aren’t single letters so it adds A LOT of stuff… But I have no choice I guess, thanks @Ben Madore
b
yw
y
You can also do this to keep the call site exactly like how it was before:
Copy code
interface A
interface B
class C : A, B

class Handler<T>

open class Handlers<T>(val list: List<Handler<in T>>)

class CHandlers : Handlers<C>(listOf(Handler<A>(), Handler<B>()))

fun main(args: Array<String>) {
    CHandlers()
    println("Hello world")
}

fun <T, H: Handler<in T>> listOf(vararg handlers: H): List<H> = handlers.toList()
Whoops you don't even need that
H
as a type param I just realised. Here's a working example without it