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