【发布时间】:2017-06-06 14:19:54
【问题描述】:
我正在尝试将此 c# 类转换为 kotlin for android:
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”行。
【问题讨论】:
-
定义“没有成功”。
-
where P : class看起来不对,class是关键字。看一下最后一个代码示例:kotlinlang.org/docs/reference/generics.html#upper-bounds -
请在您的问题中提供确切的编译错误(这可能是所有反对票发生的原因)