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和类之间没有区别。
- butterknife 7.x和Kotlin M14一起工作吗?
- 如何在Android上使用Kotlin在BottomNavigationView上设置OnNavigationItemListener?
- 如何写while循环与在kotlin中的responseInputStream.read – (while((i = responseInputStream.read(byteContainer))
- Android的奥利奥(API26)和android.app.DownloadManager
- Kotlin auto在Android Studio中完成覆盖
- 使用Parcelable时,Kotlin编译错误
- Android Studio只创建“空白活动”项目
- 使用Anko访问活动的视图
- 如何检测Data class Kotlin中更改的值?