![](/img/trans.png)
[英]Kotlin : Why *unresolved reference* for a constructor parameter of a subclass of a sealed class
[英]How to reference constructor of a sealed in Kotlin?
我有以下代碼
class A(val i: Int)
sealed class S {
class A(val i: Int)
}
fun <T> f(g: (Int) -> T) = Unit
fun test() {
f(::A) // OK
f(::S.A) // error: Unresolved reference A
}
那么如何引用密封類的構造函數呢?
我找到了一種方法: f(S::A)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.