my function returns String but in return my value is String? what should i do?
String?
means that your value can be null. So you have to check that it is not null fist
if(yourResult == null){
// handle null result, eg. throw exception, return default, etc
} else {
return yourResult // kotlin casts this to non null automatically
}
1 Like
val nullString: String? = "stuff"
nullString?.let{
println("this is your none null string ->" +it)
}