Коtlin docs example


#1

Hello, I’m new to Java and Kotlin. So, I opened kotlin-docs and found the topic “Using nullable values and checking for null”.
My question is, what should I do with function “parseInt”, that the example to work correctly.
If i copy the full example, IDEA says that i need to return something in function with block body, and it’s right.
So, should i check string on “hold an integer” and return null or Int? and why we need “parseInt” function or i don’t understand something? :slight_smile:

Thank you for your attention.


#2

This code snippet, like many other examples in the documentation, is not intended to be a full runnable example. All it is showing is that you can use a nullable return type for such a function, and how the function can be declared.


#3

I just thought that this magic function itself checks string on “hold an integer” and return null, if it’s not integer. :slight_smile: Will continue to learn Kotlin.
Thank you for your answer.