Quote:I guess what I'm really asking here is: how does one handle bad input passed to constructors?
1) Exceptions (preferred)
class Widget { Widget(int ex) { if (ex < 0) throw new IllegalArgumentException("Foo"); x = ex; }}
2) Assertions
class Widget { Widget(int ex) { assert( x >= 0); // assertions can be disabled }}
3) Forcing the values
class Widget { Widget(int ex) { if(ex >= 0) { x = ex; } else { x = 0; } }}
Factory would be another, but I wouldn't recommend it. It's simply not idiomatic Java.
With RAII in C++, people avoid exceptions like plague. In Java, exceptions are the only way to go.
What it comes down to is, what should happen when invalid value is passed. Do you wait fail-fast or fail-safe approach. Exceptions are used when handling input beyond your control. It shouldn't happen under normal use, but can happen.
Assertions are way of saying something won't happen. No ifs or buts.
Forcing the value is fail-safe, you ignore the problem. Things will work, but be careful - fail-fast is often better way. Ignoring errors unless you're sure of all the side-effects is a good way to spend hours tracking down a bug.
Your approach was right. If/else statement in constructor. Java doesn't believe in terse code, so get used to typing that same stanza over and over.