String to Int in java - Likely bad data, need to avoid exceptions

前端 未结 16 2127
迷失自我
迷失自我 2020-12-04 18:02

Seeing as Java doesn\'t have nullable types, nor does it have a TryParse(), how do you handle input validation without throwing an exceptions?

The usual way:

16条回答
  •  忘掉有多难
    2020-12-04 18:27

    You could use a Integer, which can be set to null if you have a bad value. If you are using java 1.6, it will provide auto boxing/unboxing for you.

提交回复
热议问题