Hey Should we use annotations(Like @NonNull or @Nu...
# getting-started
t
Hey Should we use annotations(Like @NonNull or @Nullable) with function arguments in kotlin to specify if function arguments are NonNull(Asking because of Null type handling in Kotlin being different) For Example
Copy code
fun callApi(@NonNull context: Context) : String{
        return "hello world!"
    }
a
Context
is already not nullable, so the annotation is superfluous
t
okkk, also i had doubt about kotlin way of handling it I mean following code :
Copy code
fun callApi( str: String) : String{
        return "hello world!"
    }
specify non null String parameter and following code :
Copy code
fun callApi( str: String?) : String{
return "hello world!"
}
means a nullable string parameter. does this makes annotations for function arguements useless?
a
It makes
@NonNull
or
@Nullable
obsolete in kotlin code, yes. These things are backed into the Typesystem. https://kotlinlang.org/docs/reference/null-safety.html
t
okkkk, that clears a lot, thanks for your help...🙂