atsushi-koshikizawa
09/26/2019, 11:37 AMWelcome to Kotlin version 1.3.50 (JRE 1.8.0_202-b08)
Type :help for help, :quit for quit
>>> "123".toInt()
res0: <http://kotlin.Int|kotlin.Int> = 123
>>> "123".toIntOrNull()
res1: <http://kotlin.Int|kotlin.Int>? = 123
wasyl
09/26/2019, 12:12 PMkarelpeeters
09/26/2019, 12:16 PM"123".toIntOrNull() != null
wasyl
09/26/2019, 12:18 PMMatteo Mirk
09/26/2019, 3:06 PMnapperley
09/27/2019, 12:48 AMnull
when there are much better ways to represent default values. Strongly prefer the toInt()
option which encourages good practise, and will not cause the program to terminate. In the worst case scenario the program will crash but will continue to run, which is very important for industrial software.karelpeeters
09/27/2019, 5:39 AMnull
means it doesn't parse correctly, it's not like you're throwing away important exception information.