Is it fine to use assertions for input validation and such purposes, in production code?
No. Refer to the first link you posted (which actually says that assertions should never be triggered in production code, not that they should never be used): assertions are not even switched on by default when running the JVM. So your validation would fail most of the time. Assertions are specifically there as a debugging tool - to check that your code is correct. The assertions that are added in the generated controller code are good examples: they check that the @FXML
-annotated fields in the controller have elements in the FXML
file with matching fx:id
attributes. If this fails, it's a programming error, not a data validation error.
Can we do something else then the usual behavior when the Boolean expression turns false, like some alternative method call or something (an example would be nice).
Just use an if (...) { ... } else { ... }
construct?