Does Kotlin Multiplatform support native generic t...
# multiplatform
a
Does Kotlin Multiplatform support native generic type parameters? Or are they stripped?
r
What do you mean by "native generic type parameters"?
a
Example, I’ve got a class:
Copy code
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.
r
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.
a
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:
Copy code
__attribute__((objc_runtime_name("KotlinMutableSet")))
__attribute__((swift_name("KotlinMutableSet")))
@interface SharedcodeMutableSet<ObjectType> : NSMutableSet<ObjectType>
@end;
g
Yes, collections have special handling of generics and you can use them from Swift
a
Ok, thanks for the input everyone 🙂