I had a function outside a class that performs some checks before making the object from the class. If the incoming parameter was faulty, it would return null instead of the object.
Then it occured to me that it would be nicer to have this function as a 2nd constructor inside the class (also returning null when failed). But I thought to return null we can leave the constructor early, thus stopping the object from being made. This doesn’t work, so is this even possible?
Here is my new constructor:
// ------------------------------
Formula (String in_) {
// parseStringToFormula
Formula myFormula=null;
fullText=in_;
if (in_.charAt(0)!='=') {
// this = null;
return; // !!!!!!!!!!!!
}
........
......
Thanks to all!
Warmest regards and a great 2025,
Chrisir