Kotlin 编译错误:Unresolved reference: mutableListOf

文章目录

    下面一段 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 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式