Search code examples
kotlin

Why toUpperCase() is deprecated if uppercase() is experimental?


I got warnings telling me that toUpperCase : String is deprecated and that I need to use uppercase instead. But when using uppercase I have to add the @OptIn(ExperimentalStdlibApi::class) annotation. Which to me does not make sense.

Why do we have to choose between a deprecated method and an experimental one ?


Solution

  • You are using a Kotlin version where the uppercase was still experimental. As of Kotlin 1.5, this is not experimental anymore.

    To solve this, update your Kotlin to 1.5 or above.

    To update Kotlin's version:

    In the root build.gradle of your project. You will find something like this:

    buildscript {
    ext.kotlin_version = '1.1.51'
    repositories {
        google()
        jcenter()
    }
    

    Change the second line to: ext.kotlin_version = '1.6.0'