Type mismatch: cannot convert from void to ArrayList

后端 未结 6 1426
别跟我提以往
别跟我提以往 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:21

    I think you should write it like this:

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

    The other way breaks making the List private. The person with the original reference can manipulate your private state.

提交回复
热议问题