在Kotlin中使用辅助构造函数
我得到一个错误: 期望成员声明在Kotlin中使用辅助构造函数,kotlin,Kotlin,我得到一个错误: 期望成员声明 类MyAdapter(val-context:context){ 构造函数(context:context,itemfos:List):RecyclerView.Adapter{ } } 我做错了什么?这样做: class MyAdapter(val context: Context): RecyclerView.Adapter<ContentItemViewHolder>() { constructor(context: Context,
类MyAdapter(val-context:context){
构造函数(context:context,itemfos:List):RecyclerView.Adapter{
}
}
我做错了什么?这样做:
class MyAdapter(val context: Context): RecyclerView.Adapter<ContentItemViewHolder>() {
constructor(context: Context, itemInfos: List<ItemInfo>): this(context) {
}
}
类MyAdapter(val-context:context):RecyclerView.Adapter(){
构造函数(context:context,itemfos:List):这个(context){
}
}
如果从另一个类继承,则应在类声明中指定它,而不是在构造函数声明中指定它。应将超类放在类声明之后:
class MyAdapter(val context: Context): RecyclerView.Adapter<ContentItemViewHolder> {
constructor(context: Context, itemInfos: List<ItemInfo>): this(context) {
}
}
类MyAdapter(val-context:context):RecyclerView.Adapter{
构造函数(context:context,itemfos:List):这个(context){
}
}
class MyAdapter(val context: Context): RecyclerView.Adapter<ContentItemViewHolder> {
constructor(context: Context, itemInfos: List<ItemInfo>): this(context) {
}
}