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;
}
}
当我尝试编译时,我得到以下内容:
错误:预期
错误:',','}'或';'预期
错误:'}'预计
答案 0 :(得分:5)
不要使用引号:
public enum User { user, computer, na };
答案 1 :(得分:2)
您可以使用:
private enum User { USER, COMPUTER, NA }
另外,要允许分配,请从final
声明中删除user
关键字:
private User user;
要创建新的Car
,您可以使用:
new Car('A', User.COMPUTER, true);
答案 2 :(得分:1)
问题是双引号:
public enum User { "user", "computer", "na" };
删除它们:
public enum User { user, computer, na };