gpt4 book ai didi

java - Java 中的 "assert"

转载 作者:行者123 更新时间:2023-12-03 23:12:26 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
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”吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com