Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Kotlin中使用辅助构造函数_Kotlin - Fatal编程技术网

在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) {

    }
}