英文:
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
专注分享java语言的经验与见解,让所有开发者获益!
评论