diego-gomez-olvera
02/21/2023, 5:21 PMpublic static boolean isEmpty(@Nullable CharSequence str) {
return str == null || str.length() == 0;
}
And I would like to deprecate it for Kotlin users. I can change it to use an stdlib function
@JvmStatic
@Deprecated("Use `isNullOrEmpty`", replaceWith = ReplaceWith("str.isNullOrEmpty()"))
fun isEmpty(str: CharSequence?): Boolean = str.isNullOrEmpty()
and it will warn Kotlin users and guide them towards the stdlib function, however it will also show as @deprecated
for Java, where it is still needed (isNullOrEmpty
is InlineOnly
). Is it possible to show as deprecated only for Kotlin?Adam S
02/21/2023, 5:22 PM@JvmSynthetic
is the exact opposite of what you want... https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.jvm/-jvm-synthetic/
Maybe you could do something clever with @JvmName
...?diego-gomez-olvera
02/21/2023, 5:24 PM@JvmStatic
fun CharSequence?.isEmpty(): Boolean = isNullOrEmpty()
@JvmName("-deprecated_empty")
@Deprecated("Use `isNullOrEmpty`", replaceWith = ReplaceWith("str.isNullOrEmpty()"))
fun isEmpty(str: CharSequence?): Boolean = str.isNullOrEmpty()
ilya.gorbunov
02/21/2023, 6:33 PMkotlin.Deprecated
annotation and this deprecation should have effect only in Kotlindiego-gomez-olvera
02/22/2023, 8:36 AM@Deprecated(message = "Use `isNullOrEmpty` instead",
replaceWith = @ReplaceWith(expression = "str.isNullOrEmpty()", imports = ""))
public static boolean isEmpty(@Nullable CharSequence str) {
return str == null || str.length() == 0;
}
However from the Kotlin code it appears deprecated but without the ReplaceWith
suggestion