【发布时间】:2011-12-10 22:29:18
【问题描述】:
可能重复:
What does assert do?
什么是“断言”? “assert”关键字是干什么用的?它何时何地有用?
这是一个来自红黑树实现的方法示例:
public Node<K,V> grandparent() {
assert parent != null; // Not the root node
assert parent.parent != null; // Not child of root
return parent.parent;
}
我不知道这段代码中使用了什么“断言”。我们不能以其他方式键入此代码,例如使用“if's”代替吗?
【问题讨论】: