ChoiceFormat.setChoices confusion about format parameter type and documentation

Posted by polygenelubricants on Stack Overflow See other posts from Stack Overflow or by polygenelubricants
Published on 2010-06-12T09:20:36Z Indexed on 2010/06/12 9:22 UTC
Read the original article Hit count: 240

From the java.text.ChoiceFormat API:

setChoices(double[] limits, String[] formats): Set the choices to be used in formatting.

Parameters:

  • limits - contains [...]
  • formats - are the formats you want to use for each limit. They can be either Format objects or Strings. When formatting with object Y, if the object is a NumberFormat, then ((NumberFormat) Y).format(X) is called. Otherwise Y.toString() is called.

I'm having difficulties understanding the documentation for the formats parameter: how can you possibly pass a Format/NumberFormat object to setChoices if it's declared String[] formats?

Note that interestingly, the getters counterpart of setChoices are declared as follows:

Is this a bug in the API? Should the setter have been declared setChoices(double[], Object[]) instead, or am I not understanding how to use setChoices correctly?

© Stack Overflow or respective owner

Related posts about java

Related posts about string