I know this can be done in Ada but I’m new to Java and don’t know if I can do this. I would like to make a radian of float subtype from 0 to 2pi. Values outside the range would be considered out of range and through a constraint error. Any help is appreciated!
Share
commons.lang.math.Range just specifies the range constraint. It does not represent a value in that range (which I think is what you want).
You could create a new class to hold the value and enforce the constraint. Your own program would pass instances of this class around and would thus get the type safety (of having the constraint enforced). When calling other API, you have to revert back to sending and accepting regular double values. You can check the constraint again before accepting return values.