-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