0
public class Car
{

    public enum User { "user", "computer", "na" };

    private char car;
    private final User user;
    private boolean call;

    public Car(char object, User user, boolean call)
    {
        this.car = car;
        this.user = user;
        this.call = call;
    }

        public User getUser()
        {
        return user;
        }

    public void setUser(User user)
    {
        this.user = user;
    }

}

当我尝试编译时,我得到以下信息:

错误:预期

错误:',', '}' 或 ';' 预期的

错误:“}”预期

4

3 回答 3

5

不要使用引号:

public enum User { user, computer, na };
于 2013-01-19T17:54:00.673 回答
2

你可以使用:

private enum User { USER, COMPUTER, NA }

此外,要允许分配,请final从 的声明中删除关键字user

private User user;

要创建一个新的Car,您可以使用:

new Car('A', User.COMPUTER, true);
于 2013-01-19T17:56:25.767 回答
1

问题是双引号:

public enum User { "user", "computer", "na" };

删除它们:

public enum User { user, computer, na };
于 2013-01-19T17:55:04.097 回答