-1
我试图转换此C#类科特林为Android:Kotlin:如何在类中使用多个Generic?
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”行。
定义'没有成功'。 – nhaarman
'其中P:class'看起来不对,'class'是关键字。看看最后一个代码示例:https://kotlinlang.org/docs/reference/generics.html#upper-bounds –
请在您的问题中提供确切的编译错误(这可能是为什么所有的投票都发生了) – voddan