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

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

问题描述

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

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&lt; String&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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