io.codemodder.codemods.HardenStringParseToPrimitivesCodemod.description.md Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of core-codemods Show documentation
Show all versions of core-codemods Show documentation
Codemods for fixing common errors across many Java projects
This change updates `String`-to-number conversions by leveraging the intended parse methods.
This change makes developer intent clearer, and sometimes with a more concise expression.
Our changes look like this:
```diff
String number = "7.1";
- int integerNum = Integer.valueOf(number);
+ int integerNum = Integer.parseInt(number);
- float floatNumVal = Float.valueOf(number).floatValue();
+ float floatNumVal = Float.parseFloat(number);
- int integerNumber = new Integer(number);
+ int integerNumber = Integer.parseInt(number);
```