JDK-6431110 : [Fmt-Nu] NumberFormat should specify the return type better
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-05-26
  • Updated: 2025-03-21
  • Resolved: 2025-03-21
Related Reports
Relates :  
Description
NumberFormat provides a number of methods to get a NumberFormat back. For example, you can use getCurrencyInstance to get one back for currency. None of these methods indicate what objects you'll get back when you invoke parseObject. This is made even more confusing by the fact that the return type may vary. For example, currency instance appears to return Long if passed in something like '$1.00' but double if passed in '$1.01'. This is unexpected and should most definitely be documented.

Comments
I don't think this is an issue. This method is specified that it is equivalent to calling `NumberFormat.parse(String, ParsePosition)`, which indicates a Number is returned. More specific logic of the Number sub-type returned is delegated to implementation classes. For example, `DecimalFormat.parse(String, ParsePosition)` provides details that discuss what sub-type of Number is returned. Thus the caller should expect Number, if the NumberFormat implementation is unknown. Pattern matching can be done to identify the implementing class, and from there a more specific Number sub-type can be inferred according to the documentation.
21-03-2025