migrator / guava-libraries-2

Guava: Google Core Libraries for Java 1.6+
0 stars 0 forks source link

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

Open migrator opened 10 years ago

migrator commented 10 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

relevance: 2

migrator commented 10 years ago

summary: Not Defined (No comment was entered for this change.)

status Not Defined creator: cgdecker@google.com created at: Aug 29, 2014

migrator commented 10 years ago

summary: Not Defined

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 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.)

status Not Defined creator: cpov...@google.com created at: Aug 29, 2014