我是否可以将所有私有(private)数据类型保存在抽象类中,以便稍后可以使用存储在数组列表中的信息(数组列表位于不同的类中)。我已经成功地存储了之前的所有字符串,但我的 boolean 值没有成功。我知道数组列表用于引用对象。谢谢
public abstract class Room
{
private String roomID;
private boolean ensuite;
private String guest;
private String nights;
private String booked;
public abstract room (String roomID boolean ensuite)
}
最佳答案
这是否是从您的代码中准确复制的? String roomId
和 boolean ensuite
之间缺少 ,
。方法声明中也不需要抽象。
试试这个:
public abstract class Room
{
private String roomID;
private boolean ensuite;
private String guest;
private String nights;
private String booked;
public Room (String roomID, boolean ensuite)
{
this.roomID = roomID;
this.ensuite = ensuite;
//so on...
}
}
关于java - 使用字符串将 boolean 变量传递给 Arraylist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8702159/