I am having trouble getting this code to work. Run...
# announcements
s
I am having trouble getting this code to work. Running into the issue shown in the pic.
Copy code
class Extractor<in T, out R, out O>(
    private val prop: KProperty1<T, R>,
    private val func: (R) -> O
) {
    fun extract(receiver: T): O {
        return func(prop.get(receiver))
    }
}

class Marshaller<T : Any> {
    private val extractors: MutableList<Extractor<*, *, *>> = arrayListOf()

    fun <R : Any, O : Any> toAttr(
        prop: KProperty1<T, R>,
        extractor: (R) -> O
    ) {
        extractors.add(Extractor(prop, extractor))
    }

    fun <R: Any> toAttr(prop: KProperty1<T, R>) {
        toAttr(prop) { it }
    }

    fun extractAll(receiver: T): List<Any?> {
        return extractors.map { it.extract(receiver) }
    }
}
k
Any reason why
extractors
isn't a
MutableList<Extractor<T, *, *>>
?
s
No good reason, no.
k
Then do that, it fixes your issue.
s
Haha thanks @karelpeeters