[JSR-354] Re: Further Feedback on the API
- From: Stephen Colebourne <scolebourne@...>
- To: jcurrency_mail@...
- Subject: [JSR-354] Re: Further Feedback on the API
- Date: Thu, 10 Oct 2013 16:02:39 +0100
On 10 October 2013 15:39, Werner Keil <werner.keil@...> wrote:
>> BTW, the Javadoc/spec should reserve the method name getAmount(). That
>> allows the JDK integration to add a default method returning
>> BigDecimal/Rational if the JDK adds it.
> You're talking about MonetaryAmount Javacod/spec, right?
> Assuming a small code snippet like
> MonetaryAmount amount = Money.of("CHF", 100);
> Could sound a bit confusing, but maybe I am the only one who finds it
MonetaryAmount matches TemporalAmount in naming.
> Either getNumericAmount(), getNumber() that's how ICU4J calls it, if it's
> left out of the interface, a concrete implementation may return ANY valid
> numeric type, if the interface declared it as
> Number getNumber()
> the implementation can override that and return a concrete type like
> BigDecimal having the full power and precision within its scope while the
> portable interface has what Number offers, try it...
> or other alternatives like getValue() crossed my mind. The latter is what
> JScience/JSR-275 or its successors Unit-API use, either with or without the
> get* prefix.
Number is OK for implementors (so long as the object creation is not a
problem). But it is useless for consumers of the API. The only way to
get data out of a Number with any accuracy is repeated instanceof
Note that the API will always be a compromise. JSR-310 does not
support fractional amounts such as 3.5 hours, though you can express 3
hours and 30 minutes which is equivalent. For money, we could say that
we support only decimal fractions, but it doesn't save a lot here.