-
Enhancement
-
Resolution: Won't Fix
-
P4
-
5.0
-
generic
-
generic
Name: nl37777 Date: 06/27/2003
RFE 4881738 changed one method in java.text.MessageFormat
to use varargs syntax. The varargs syntax makes MessageFormat much
easier to use, so this is a good change, but it is incomplete. To
complete it, additional changes are needed.
There are two other methods on MessageFormat that are commonly used and
take an Object[] as the last parameter. Both are originally declared in
Format, and therefore declare the Object[] as just Object:
public final String format(Object obj) // in Format
public AttributedCharacterIterator formatToCharacterIterator(Object
arguments)
To make these use varargs, we need to add new overloads:
public String format(Object... arguments)
public AttributedCharacterIterator
formatToCharacterIterator(Object... arguments)
In the past the two existing methods, even though specified to accept
one Object, would in reality require an Object[]. According to the
varargs resolution mechanism, calls that provide only one Object would
go to the old methods instead to the varargs methods, because varargs
is considered only in a second pass. This means we need to change
public AttributedCharacterIterator formatToCharacterIterator(Object
arguments)
and override
public String format(Object obj)
to handle the case where a single non-array Object comes in, and wrap
it into an array. This also means making Format.format(Object)
non-final.
Finally, since we now accept single non-array objects in the above two
methods, we should do the same in
public StringBuffer format(Object arguments, StringBuffer result,
FieldPosition pos)
The following two methods cannot be changed to varargs syntax because
this syntax is only allowed for the final parameter:
public final StringBuffer format(Object[] arguments, StringBuffer
result,
FieldPosition pos)
public final StringBuffer format(Object arguments, StringBuffer
result,
FieldPosition pos)
======================================================================