I used to insert java1.4's assertion construct in my codes and find it really practical because it allows me to enable the inserted assertions in debug- time and disable them at compile-time.
My question is:
whether it is possible to do the same thing to the modern Preconditions.checkArgument(..) etc in Guava's library?
This is important to know. We may have plenty of guava's precondition check in the codes, but most of them are for debugging purpose and may affect performance when the number of such preconditions quickly becomes large.
Thank you for your idea.
No, there isn't. If you really want to take off your seatbelts when you're driving at high speed, use assert
instead.
In my experience, most preconditons are really cheap - and very unlikely to have a significant performance impact in real life. (Whereas the impact of unexpected bad data getting into your system and not being detected until it's messed everything else up can be huge...)