If I have a function that takes a `String` and par...
# getting-started
d
If I have a function that takes a
String
and parses it to return some
MyDataClass
, is it idiomatic in Kotlin to return
MyDataClass?
which is
null
if the input String doesn't match the pattern? Or should I use a
Result
or throw an exception or something? In this case returning
null
would happen "normally" and would not be exceptional in any way
Great, thanks. I think my particular use case is definitely the last category.
e
A sealed class instead of an null maybe another option
You are right. It was "maybe" Also I am starting with kotlin so my opinion is too weak. I came from Java where we love null (and nullPointerException) 🤪