alex.hart

    alex.hart

    3 years ago
    Does Kotlin Multiplatform support native generic type parameters? Or are they stripped?
    r

    Ruckus

    3 years ago
    What do you mean by "native generic type parameters"?
    alex.hart

    alex.hart

    3 years ago
    Example, I’ve got a class:
    public abstract class A<T> {
    }
    When I compile it and look at it’s declaration in the header,
    T
    is gone, and Swift will error if I try to create an
    A
    with a type parameter
    I can see platform level classes have their type parameter specified, but I’m not sure why it is not generating this for my common module types.
    russhwolf

    russhwolf

    3 years ago
    Swift is not aware of Kotlin's generics because it passes through Objective-C which doesn't support them. But you should be able to use them in Kotlin/Native code running on iOS.
    alex.hart

    alex.hart

    3 years ago
    Got it. So are things like Kotlin collections etc. special cased? Because I see that they basically extend the corresponding NS* class and provide types to them. Example:
    __attribute__((objc_runtime_name("KotlinMutableSet")))
    __attribute__((swift_name("KotlinMutableSet")))
    @interface SharedcodeMutableSet<ObjectType> : NSMutableSet<ObjectType>
    @end;
    gildor

    gildor

    3 years ago
    Yes, collections have special handling of generics and you can use them from Swift
    alex.hart

    alex.hart

    3 years ago
    Ok, thanks for the input everyone 🙂