I'm writing something that handles length units, say, metres and feet. I don't want to accidentally convert between them (trying to avoid something like the Mars Climate Orbiter crash).
I'd like to use the type system for this, so that the compiler will catch these kind of errors, and only be able to convert between these types very explicitly.
I'm writing this in Java, which I'm not super familiar with. Looks like I can't subclass
How should I go about this? I guess I could define my own classes
Feet but I'd lose the benefits of automatic unboxing. If this was C++ I could add an
operator double and add arithmetic overloads to make sure I can't operate mixed types, but it looks like I can't do this in Java?