Search code examples
functiontypeskotlinuuid

Kotlin Type Mismatch for a function return a string


import java.util.UUID

fun UuidGenerator() {
    val id =  UUID.randomUUID().toString();
    return id.replace("-", "")
}

^^^ UuidGenerator.kt

Just try to build a simple UUI generator function so I can import it into a class and use it to generate random string of 32 characters, but keep getting type mismatch.

enter image description here


Solution

  • You need to specify return object : String

    fun UuidGenerator() : String {
       val id =  UUID.randomUUID().toString()
       return id.replace("-", "")
    }