Java assertions underused

前端 未结 11 2128
独厮守ぢ
独厮守ぢ 2020-12-04 21:16

I\'m wondering why the assert keyword is so underused in Java? I\'ve almost never seen them used, but I think they\'re a great idea. I certainly much prefer the

11条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 21:42

    @Don, you are frustrated that assertion are turned off by default. I was also, and thus wrote this little javac plugin that inlines them (ie emits the bytecode for if (!expr) throw Ex rather than this silly assert bytecode.

    If you include fa.jar in your classpath while compiling Java code, it will do its magic and then tell

    Note: %n assertions inlined.
    

    @see http://smallwiki.unibe.ch/adriankuhn/javacompiler/forceassertions and alternatively on github https://github.com/akuhn/javac

提交回复
热议问题