CharSequence.isEmpty()

I am using Kotlin version 1.4.10 for JVM and Java version 15. I have a String property named text. When I write if (text.length == 0), IDEA suggests that I “Replace size zero check with isEmpty”. But when I accept that suggestion and write if (text.isEmpty()), then I get the warning that “isEmpty():Boolean is deprecated”. I suspect that the problem is related to the fact that I recently upgraded to Java 15, and Java 15 added a default method isEmpty() to interface CharSequence, but in searching the Kotlin documentation for a deprecation, I could not find it. Perhaps IDEA should be modified to accept the ‘isEmpty()’ method from Java without declaring it as deprecated, and possibly the documentation for Kotlin should be updated to reflect this.

6 Likes

JDK15 introduced its own isEmpty() method on CharSequence, which clashes with Strings.kt’s extension on CharSquence with the exact same signature. I guess that is an automatic deprecation emitted by the kotlin compiler to warn about this.

2 Likes