Dear developers, I'm a graduate student doing software engineering research. Recently, I came across some interesting facts about Java assert statements and have a few questions to ask.
Although the assert keyword has been around for a long time and is handy for invariant checks, it does not seem to be widely used. For example, in the famous j.u.c packages, nearly all assert statements are commented out [1]. My questions are, should assert be heavily used in Java programs, especially in production code? And should we enable them in the production code? By the way, I have read a useful article about using assertions in Java [2], but it does not provide clear answers to my questions above. Thank you in advance! [1] https://github.com/search?q=repo%3Aopenjdk%2Fjdk+assert+path%3A%2F%5Esrc%5C%2Fjava.base%5C%2Fshare%5C%2Fclasses%5C%2Fjava%5C%2Futil%5C%2Fconcurrent%5C%2F%2F&type=code [2] https://docs.oracle.com/javase/8/docs/technotes/guides/language/assert.html Regards, Daohan Qu