User loginNavigation |
archivesStrongly typed quantities in JavaAn interesting project at jscience.com. From their description:
Let's take the following example:
class Person {
void setWeight(double weight);
}
Should the weight be in pound, kilogram ??
With quantities there is no room for error:
class Person {
void setWeight(Quantity<Mass> weight);
}
Not only the interface is cleaner (the weight has to be of mass type);
but also there is no confusion on the measurement unit:
double weightInKg = weight.doubleValue(SI.KILOGRAM);
double weightInLb = weight.doubleValue(NonSI.POUND);
Quantities work hand-in-hand with units (also parameterized).
For example, the following would result in compile-time error:
double weightInGal = weight.doubleValue(NonSI.GALLON); // Compile error, Unit<Mass> required.
---- New Fortress ReleaseFortress Language spec 0.866 [sin pi/3] is out! http://research.sun.com/projects/plrg/fortress0866.pdf By Edson Manoel at 2006-03-07 16:32 | Site Discussion | login or register to post comments | other blogs | 7668 reads
|
Browse archivesActive forum topics |
Recent comments
5 weeks 4 days ago
5 weeks 5 days ago
6 weeks 1 hour ago
6 weeks 1 hour ago
6 weeks 5 days ago
6 weeks 5 days ago
6 weeks 5 days ago
9 weeks 5 days ago
10 weeks 4 days ago
10 weeks 4 days ago