Can I deprecate or warn if a `fun` in used in kotl...
# getting-started
f
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
You could call it something like doNotCallFromKotlin and then use
@JvmName
to give it a decent name when called from Java?
😮 1
f
woot, that is a nice trick 👍
👍 1
e
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
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
IDEA is clever enough to warn when using deprecated Kotlin APIs in Java, but as long as you can ignore that…