例如在Java中我可以這樣寫:交叉引用參數
public abstract class Element<S extends Snapshot> { ... }
public abstract class Snapshot<E extends Element> { ... }
,然後某處,擴展這一類:
public class SnapshotImpl extends Snapshot<ElementImpl> { ... }
public class ElementImpl extends Element<SnapshotImpl> { ... }
但是,當我試圖實現科特林同一類層次結構:
abstract class Element<S : Snapshot>
abstract class Snapshot<E : Element>
我得到了下面的編譯錯誤:
Error:(6, 28) Kotlin: One type argument expected for class Snapshot<E> defined in model Error:(6, 25) Kotlin: One type argument expected for class Element<S> defined in model
是否有任何方法可以在Kotlin中重現相同類型的參數限制?