Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do you have any tips to effectively use Java Assert?

I don't see much of the developer using Java Assert, but I am very keen in using them. Could you share some tips to effectively use them?

like image 341
Mohan Narayanaswamy Avatar asked Dec 12 '22 22:12

Mohan Narayanaswamy


1 Answers

I use assert to check the preconditions of nonpublic methods, that's all (I do not claim doing design-by-contract). Just in case, let me remind what Programming With Assertions writes about Preconditions, Postconditions, and Class Invariants:

While the assert construct is not a full-blown design-by-contract facility, it can help support an informal design-by-contract style of programming.

For full-blown support in Java, maybe consider using a third-party library (from Wikipedia):

iContract2, Contract4J, jContractor, Jcontract, C4J, CodePro Analytix, STclass, Jass preprocessor, OVal with AspectJ, Java Modeling Language (JML), SpringContracts for the Spring framework, or Modern Jass, Custos using AspectJ,JavaDbC using AspectJ, JavaTESK using extension of Java.

like image 107
Pascal Thivent Avatar answered Dec 24 '22 22:12

Pascal Thivent