类型不匹配:无法从 void 转换为 ArrayList<String> [英] Type mismatch: cannot convert from void to ArrayList&lt;String&gt;

查看:37
本文介绍了类型不匹配:无法从 void 转换为 ArrayList<String>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我收到此代码的错误?我有 ArrayList 和 Collections 的正确导入

Why am I getting this error for this code? I have the correct imports for ArrayList an Collections

private ArrayList<String> tips;

public TipsTask(ArrayList<String> tips){
    this.tips = Collections.shuffle(tips);
}

推荐答案

Collections.shuffle(tips);

Collections.shuffle 返回 void,您不能将 void 分配给 ArrayList.

Collections.shuffle return void, you cannot assign void to a ArrayList.

你可以这样做:

    Collections.shuffle(tips);
    this.tips = tips;

这篇关于类型不匹配:无法从 void 转换为 ArrayList<String>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆