tailorlala / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Overloaded versions of Ints/Longs.tryParse with a radix #1839

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please add these overloaded methods:

Ints.tryParse(String s, int radix)
Longs.tryParse(String s, int radix)

That way, Ints/Longs.tryParse could be used as drop-in replacements both String 
versions of Integer/Long.valueOf

Another thing worth thinking about would be to add similar methods that return 
Optional<Integer / Long>, forcing client code to actually react on the changed 
semantics of using tryParse rather than valueOf. Of course the question of how 
to name these methods is a nasty one. tryParse would've been a perfect naming 
choice for that

Original issue reported on code.google.com by SeanPFl...@googlemail.com on 29 Aug 2014 at 8:36

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 29 Aug 2014 at 8:33

GoogleCodeExporter commented 9 years ago
Did we have any reservations that tryParse("foo", 10) might look like it's 
providing a default value rather than a radix? I forget.

(We did give some thought to Optional<Integer> and so forth. Our reasoning for 
sticking with Integer was that the method was intended to be fast. But it's not 
clear cut. For example, and extreme version of that reasoning could have led to 
our choosing to return |long| with an out-of-int-bounds value used to indicate 
invalid inputs. We could also have introduced OptionalInteger/OptionalLong 
classes.)

Original comment by cpov...@google.com on 29 Aug 2014 at 8:38

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:08

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:17

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:07