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

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

public class ChildItemCollection<P, T, C> : ICollection<T> where P : class where T : ChildItem<P> where C : class, ICollection<T> { private P _parent; private C _collection; public ChildItemCollection(P parent, C collection) { this._parent = parent; this._collection = collection; } ... } public class ChildItemCollection<P, T> : ChildItemCollection<P, T, List<T>> where P : class where T : ChildItem<P> { #region Constructors public ChildItemCollection(P parent) : base(parent, new List<T>()) { } public ChildItemCollection(P parent, ICollection<T> collection) : this(parent) { foreach (T item in collection) this.Add(item); } #endregion Constructors } 

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

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

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

 class ChildItemCollection<P, T : ChildItem<P>, C : Collection<T>> : ... 

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

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