User loginNavigation |
Strongly 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.
---- By shahbaz at 2006-03-07 03:27 | LtU Forum | previous forum topic | next forum topic | other blogs | 7154 reads
|
Browse archives
Active forum topics |
Recent comments
2 days 22 hours ago
3 days 19 hours ago
4 days 23 hours ago
5 days 9 min ago
1 week 3 days ago
1 week 3 days ago
1 week 3 days ago
4 weeks 3 days ago
5 weeks 2 days ago
5 weeks 2 days ago