unitsofmeasurement / indriya

JSR 385 - Reference Implementation
Other
119 stars 42 forks source link

Should we add ComparableQuantity.of()? #363

Closed keilw closed 2 years ago

keilw commented 2 years ago

Similar to the JDK Map or List interfaces, we could add a static method ComparableQuantity.of() to call directly on the interface. It may seem as a convenience method at first, but would allow to explore further pushing such methods up into the API, where this could work as well, but possibly not before a major release (to be explored, potentially in a MR2)

keilw commented 2 years ago

Looking at Map.of() or List.of() in 20 or more variations of arguments, all of those are merely convenience methods for the ImmutableCollections. The method name is not self-descriptive because all of these should rather say ofImmutable() or similar, instead of just of(). That's bad naming and design and does not really add value over using the central Quantities factory class.

If there was a way, Quantity itself could tap into the SPI classes like QuantityFactory and have a static Quantity.of(Number, Unit) method, then that would make more sense in the API, but we'd have to find a generic way instead of having to pass the Class of the quantity type.