Kotlin:如何在类中使用多个Generic?

我试图将这个C#类转换为Android的kotlin:

public class ChildItemCollection

: ICollection where P : class where T : ChildItem

where C : class, ICollection { private P _parent; private C _collection; public ChildItemCollection(P parent, C collection) { this._parent = parent; this._collection = collection; } ... } public class ChildItemCollection

: ChildItemCollection<P, T, List> where P : class where T : ChildItem

{ #region Constructors public ChildItemCollection(P parent) : base(parent, new List()) { } public ChildItemCollection(P parent, ICollection collection) : this(parent) { foreach (T item in collection) this.Add(item); } #endregion Constructors }

我尝试了很多事情,但都没有成功。

我不明白如何使用“where”行。

在Kotlin中,你可以在声明中指定types参数的上限:

 class ChildItemCollection, C : Collection> : ...

如果你有多个上限,他们应该与where分开指定,参见另一个问答 。

此外,Kotlin没有class上限,因为值types和类之间没有区别。