[英]Why kotlin cannot expand my typealias?
我想编写如下代码:
typealias Just<T> = T // Error here
val hello: Just<String> = "hello"
我说Kotlin: Type alias expands to T, which is not a class, an interface, or an object
出错Kotlin: Type alias expands to T, which is not a class, an interface, or an object
。
我猜想typealias是编译时的功能,类型擦除不应该包含任何内容。 那么,为什么我不能这样写typealias
?
你不能写这样的代码,因为科特林编译器的开发者认为没有用例支持类型的别名,来扩大输入参数( Just
基本上是这样一个类型别名的唯一可能的声明),因此并没有设计和实现对它的支持。 这确实与类型擦除无关。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.