繁体   English   中英

为什么Kotlin无法扩展我的Typealias?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM