Type mismatch: cannot convert from void to ArrayList

后端 未结 6 1312
别跟我提以往
别跟我提以往 2021-01-21 03:54

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

private ArrayList tips;

public TipsTask(ArrayLi         


        
6条回答
  •  生来不讨喜
    2021-01-21 04:00

    You should call it like this:

    private ArrayList tips;
    
    public TipsTask(ArrayList tips){
        this.tips = tips;
        Collections.shuffle(tips);
    }
    

    Collections.shuffle(tips) modifies the ArrayList directly. It does not need to create a copy.

提交回复
热议问题