RFR(S): 8055032: Improve numerical parsing in java.net and sun.net

Peter Levart peter.levart at gmail.com
Fri Aug 15 08:36:20 UTC 2014


On 08/14/2014 02:00 PM, Alan Bateman wrote:
> On 14/08/2014 12:42, Claes Redestad wrote:
>>
>> Noone brought it up, as far as I can recall. Since parseInt(String, 
>> int radix) already existed, I figured adding the range parameters to 
>> the end would be overall less awkward than to push the radix 
>> parameter right in the new methods. The chosen implementation 
>> maintains that the second parameter is always radix, which I think 
>> helps maintain consistency.
> I think consistency could be argued both ways as the radix is also the 
> last parameter in the existing methods. When I look at this method:
>
> public static int parseInt(CharSequence s, int radix, int beginIndex, 
> int endIndex)
>
> and then feels more error prone than if the beginIndex/endIndex were 
> immediately after the CharSequence.
>
> I'm interested in other opinions on this.
>
> -Alan.

'radix' parameter could be typed as short. It typically is called with a 
constant literal and beginIndex/endIndex are usually int expressions. 
This would catch majority of mistakes where the caller mixes the order. 
But would not be consistent with public methods though...


Peter

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/net-dev/attachments/20140815/e1e53197/attachment-0001.html>


More information about the net-dev mailing list