On Tue, 6 Feb 2024 22:31:32 GMT, Justin Lu <j...@openjdk.org> wrote:

>> src/java.base/share/classes/java/text/MessageFormat.java line 681:
>> 
>>> 679:         if (fmt instanceof NumberFormat) {
>>> 680:             // Add any instances returned from the NumberFormat 
>>> factory methods
>>> 681:             if (fmt.equals(NumberFormat.getInstance(locale))) {
>> 
>> This looks like wack-a-mole code, no good design; likely to be hard to 
>> maintain.
>> (I don't have a better idea at the moment though).
>
> I agree, it was the existing design that caused for example, 
> CompactNumberFormat to not automatically be supported by MessageFormat. A 
> simple alternative would be storing the potential pre-defined NumberFormats 
> in some data structure that we could just iterate through to feel less “whack 
> a mole” like, but that array would still suffer from the same maintenance 
> issues. I’ll try to think of something better.

One idea would be to delegate to a (package-private) method in the formatXXX 
class. 
That would localize to the respective class the details.
(An abstract protected method might be preferred, but its not worth creating 
extra public API surface area for this).

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/17663#discussion_r1480644067

Reply via email to