Kotlin 编译错误:Unresolved reference: mutableListOf

更新日期: 2020-01-12 阅读次数: 11167 字数: 88 分类: Kotlin

下面一段 Kotlin 代码在编译时报错:

class ResultListAdapter(val resultList: mutableListOf<PercentPrice>):
        RecyclerView.Adapter<ResultListAdapter.ResultViewHolder>() {

报错信息为:

Unresolved reference: mutableListOf

原来,mutableListOf 是一个函数方法,只能在类型 MutableList 初始化时使用。

所以,这里应该使用类 MutableList。

class ResultListAdapter(val resultList: MutableList<PercentPrice>):
        RecyclerView.Adapter<ResultListAdapter.ResultViewHolder>() {

mutableListOf 的使用范例

val prices = mutableListOf<PercentPrice>()

关于作者 🌱

我是来自山东烟台的一名开发者,有敢兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊, 查看更多联系方式