Search code examples
javaassert

java equivalent of assert( 0 && "description")


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?


Solution

  • 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