https://kotlinlang.org logo
#getting-started
Title
# getting-started
f

frogger

05/31/2022, 6:08 AM
Can I deprecate or warn if a
fun
in used in kotlin but issue no warning in java? We created a “bridge function” for java which should be avoided in kotlin code. I thought it would be nice to show a warning if used accidentally in kotlin code.
r

Rob Elliot

05/31/2022, 6:27 AM
You could call it something like doNotCallFromKotlin and then use
@JvmName
to give it a decent name when called from Java?
😮 1
f

frogger

05/31/2022, 6:33 AM
woot, that is a nice trick 👍
👍 1
e

ephemient

05/31/2022, 9:22 AM
also a @RequiresOptIn annotation can be used to guard against Kotlin usage, without affecting Java callers (although there may be an IDE warning in the future https://youtrack.jetbrains.com/issue/KTIJ-15207)
y

Youssef Shoaib [MOD]

06/02/2022, 11:50 AM
You can do
@Deprecated
which only deprecates on Kotlin. In fact, Deprecated has an option of
WarningLevel.ERROR
(can't remember the exact syntax and I'm on mobile lol)
e

ephemient

06/02/2022, 9:56 PM
IDEA is clever enough to warn when using deprecated Kotlin APIs in Java, but as long as you can ignore that…
2 Views