Kotlin 小写函数

Kotlin lowercase Function

我是 kotlin 的新手,如果这是一个简单的错误,我提前道歉。

我目前正在尝试将 api(用 Kotlin 编写)重写为 java 17。 到目前为止一切正常。但现在我收到以下已弃用的消息:

'toLowerCase(): String' 已弃用。请改用 lowercase()。

我当然知道是什么意思了,所以我试着做了如下图: https://i.stack.imgur.com/vT8k5.png

但是为什么找不到小写函数?

这是我的 build.gradle:

plugins {
    id 'org.jetbrains.kotlin.jvm'
    id "org.jetbrains.kotlin.kapt"
    id "org.jetbrains.dokka"

    id "java-library"
    id "maven-publish"

    id "jacoco"
    id "io.gitlab.arturbosch.detekt"
    id "org.jlleitschuh.gradle.ktlint"

    id "com.github.gmazzo.buildconfig"
}

apply from: "${rootDir}/gradle/dependencies.gradle"

tasks.withType(org.jetbrains.dokka.gradle.DokkaTask).configureEach {
    dokkaSourceSets {
        configureEach {
            sourceLink {
                localDirectory.set(file("src/main/kotlin"))
                remoteUrl.set(uri("").toURL())
            }

            externalDocumentationLink { url.set(new URL("https://square.github.io/retrofit/2.x/retrofit/")) }
            externalDocumentationLink { url.set(new URL("https://square.github.io/okhttp/3.x/okhttp/")) }
            externalDocumentationLink { url.set(new URL("https://square.github.io/moshi/1.x/moshi/")) }
        }
    }
}

tasks.dokkaJavadoc.configure {
    outputDirectory.set(javadoc.destinationDir)
}

task sourceJar(type: Jar) {
    archiveClassifier = "sources"

    from sourceSets.main.allSource
}

task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
    archiveClassifier = "javadoc"

    from javadoc.destinationDir
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
    kotlinOptions {
        jvmTarget = "17"
        allWarningsAsErrors = true
        freeCompilerArgs = ["-Xjsr305=strict", "-progressive"]
    }
}

kapt {
    useBuildCache = true
}

test {
    finalizedBy jacocoTestReport

    useJUnitPlatform()
}

buildConfig {
    packageName("my.package")  // forces the package. Defaults to '${project.group}'

    useKotlinOutput()   // adds `internal` modifier to all declarations
    buildConfigField("String", "packageName", "\"my.package\"")
    buildConfigField("String", "version", provider { "\"${project.version}\"" })
}

jacoco {
    setToolVersion(jacocoVersion)
}

jacocoTestReport {
    reports {
        xml.required = true
        html.required = false
    }
}

ktlint {
    disabledRules = ["import-ordering"]
    version = ktlintVersion

    reporters {
        reporter "checkstyle"
    }
}

detekt {
    version = detektVersion
    buildUponDefaultConfig = true

    config = files("$rootDir/config/detekt.yml")
}

repositories {
    mavenCentral()
}
dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
}
compileKotlin {
    kotlinOptions {
        jvmTarget = "17"
    }
}
compileTestKotlin {
    kotlinOptions {
        jvmTarget = "17"
    }
}

确保您的 kotlin-stdlib 版本为 1.5 或更高版本。检查 this