How to implement a java.text.Format
<p>I wanted to create an extension of <a href="http://docs.oracle.com/javase/7/docs/api/java/text/Format.html" rel="nofollow"><code>java.text.Format</code></a> but I do not know what to do with the <a href="http://docs.oracle.com/javase/7/docs/api/java/text/Format.html#parseObject%28java.lang.String%29" rel="nofollow"><code>Format.parseObject</code></a> method. The javadoc states</p>

<blockquote>
  <p>Parses text from the beginning of the given string to produce an object. The method may not use the entire text of the given string.</p>
</blockquote>

<p>So if you want to implement this method, how do you handle the situation where you can parse the whole input string ? Do you throw an exception or do you return the parsed value (or something else ) ? Note that the javadoc for the exception states that a <code>ParseException</code> is thrown</p>

<blockquote>
  <p>if the beginning of the specified string cannot be parsed.</p>
</blockquote>

<p>IMO, in case where I can parse the whole <code>String</code>, I certainly can parse the beginning so no reason to throw an exception. Looking at the implementation of this method in the JDK, they do not seem to respect their own documentation</p>

<pre><code>public Object parseObject(String source) throws ParseException {
    ParsePosition pos = new ParsePosition(0);
    Object result = parseObject(source, pos);
    if (pos.index == 0) {
        throw new ParseException("Format.parseObject(String) failed",
            pos.errorIndex);
    }
    return result;
}
</code></pre>
