【发布时间】:2011-09-13 09:49:44
【问题描述】:
是否可以使用逻辑运算符“!”在具有 true 或 false 值的对象上?专门针对这样的对象?
public class Briefcase {
private final double amount;
private final String model;
private boolean removed = false;
private String face;
public Briefcase(double amount, int face, String model) {
this.face = Integer.toString(face);
this.amount = amount;
this.model = model;
}
public double getAmount() {
return amount;
}
@Override
public String toString() {
return face;
}
public String getModel() {
return model;
}
public void remove() {
removed = true;
face = "X";
}
public boolean isRemoved() {
return removed;
}
}
然后像这样使用它
Briefcase[] cases = new Briefcase[];
if (!cases[5].isRemoved()) { .... block of code}
这可能吗?如果是这样,请向我提供该文档和其他示例的链接,我觉得这很奇怪,同时也很有趣
【问题讨论】:
-
问题是你问的是一个关于array 公文包的问题......而不是单个项目。您如何期望它起作用?
-
与在这里提出问题并坐下来相比,编码和执行所需的时间更少。为什么不做一个实验主义者?让JDK告诉你正确答案。
标签: java oop boolean boolean-logic unary-operator