The type of the expression must be an array type but it resolved to float

后端 未结 3 1012
不知归路
不知归路 2021-01-28 15:19

I hit a bump when I\'m doing my Java code. I feel like I somehow got the concept messed up, like I not sure for this:

void setScore(float[] sco)
{
    sco = scor         


        
3条回答
  •  心在旅途
    2021-01-28 16:02

    I guess you mixed up the variable names:

    void setScore(float[] sco)
    {
        sco = score;
    }
    
    public void setScore(float sco, int id)
    {
        sco[id] = score;
    }
    

    because score is the field which you want to populate and sco is the parameter which you want to populate score with. The code above does not change any contents of Score, so try to swap it to

    void setScore(float[] sco)
    {
        this.score = sco;
    }
    
    public void setScore(float sco, int id)
    {
        this.score[id] = sco;
    }
    

    it also would have helped if you have started using this to mark instance fields explicitly.

提交回复
热议问题