As mentioned in Kotlin API document, readLine() returns the line read or null if end of file has already been reached but it is the same functionality as readlnOrNull(). So what is the difference here?
I know that readlnOrNull() and readln() have been introduced in Kotlin 1.6 for the purpose of null safety but I can't understand why readlnOrNull() introduced when readLine() exist before.
They added
readlnOrNullas an alias ofreadLinefor the sake of preserving the convention that each standard library function that throws a RuntimeException has an “orNull” version that returns null instead of throwing. It was added whenreadlnwas added. It’s so the matching function with this behavior can be easily found. IfreadLnhad existed from the earliest version of Kotlin, then they might never have created a redundantreadLinefunction that matches the behavior ofreadlnOrNull. They have not deprecatedreadLinebecause there’s nothing wrong with its behavior and it’s concise.