英文:
java equivalent of assert( 0 && "description")
问题
什么是Java中与此相当的内容?
assert(0 && "description");
我尝试过
assert(false && "description");
但是Java的类型对此要求太严格了。在断言语句中添加描述的惯用方式有什么提示吗?
英文:
What is the Java equivalent this?
assert(0 && "description");
I've tried
assert(false && "description");
But Java types are too strict for that. Any tips on the idiomatic way to add a description to an assert statement?
答案1
得分: 2
你可以使用以下方式为断言添加描述:
assert false : "description";
在https://docs.oracle.com/javase/8/docs/technotes/guides/language/assert.html上有描述为:
assert Expression1 : Expression2 ;
英文:
You can add a description to an assertion using:
assert false : "description";
This is described as
assert Expression1 : Expression2 ;
on https://docs.oracle.com/javase/8/docs/technotes/guides/language/assert.html
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论