Hi everyone, did anyone have experience about how ...
# multiplatform
m
Hi everyone, did anyone have experience about how create a function like this that could work in the same way on swift?
Copy code
class GenericClass<T> {
    fun <A> clone(block: (GenericClass<T>) -> GenericClass<A>): GenericClass<A>{
        return block(this)
    }
}
Because currently the compiler generates this implementation that not fill my requirements because the return type is GenericClass<`AnyObject`> instead of be generic
<A>
Copy code
public class GenericClass<T> : KotlinBase where T : AnyObject {
    public init()

    open func clone(block: @escaping (GenericClass<T>) -> GenericClass<AnyObject>) -> GenericClass<AnyObject>
}
Is this implementation wrong? There is a proper way to do that? Thank you!
r
Well there is nothing wrong with your implementation 🙂. The reason you are getting
AnyObject
instead of the generic
A
is because ObjC doesn't support generics on functions.
m
Thank you Rick 🙏
👍🏻 1