January 2018
Intermediate to advanced
434 pages
14h 1m
English
Kotlin uses String’s extension functions such as .toLong() and toLongOrNull() to make things easier. Let’s dive into their implementation.
public inline fun String.toLong(): Long = java.lang.Long.parseLong(this)
As you can see, internally, it also calls the Long.parseLong(string) Java static method, and it is similar to the other data types.
public inline fun String.toShort(): Short = java.lang.Short.parseShort(this)
public inline fun String.toInt(): Int = java.lang.Integer.parseInt(this)
public inline fun String.toLong(radix: Int): Long = java.lang.Long.parseLong(this, checkRadix(radix))
The checkRadix
Read now
Unlock full access