我有个问题!我不知道如何返回数组?我想使用get和set。

 TypeOfWater[] waters = returnTypes1();

public String[] getTypeOfWater()
{
    return waters;//How can I rerutn array???
}


private static TypeOfWater[] returnTypes1()
{
    TypeOfWater[] type = new TypeOfWater[4];
    type[0] = new TypeOfWater();
    type[0].name = "1)Fanta";
    type[0].cost = 11;

    type[1] = new TypeOfWater();
    type[1].name = "2)Coca";
    type[1].cost = 12;

    type[2] = new TypeOfWater();
    type[2].name = "3)Sprite";
    type[2].cost = 14;

    type[3] = new TypeOfWater();
    type[3].name = "4)Orange juice";
    type[3].cost = 22;

    return type;
}

请帮我。我是Java编程的新手。

最佳答案

你应该改变

public String[] getTypeOfWater()
{
    return waters;//How can I rerutn array???
}


对于

public TypeOfWater[] getTypeOfWater()
{
    return waters;//How can I rerutn array???
}

10-07 16:12