Is there a way to deprecate a java method but only...
# announcements
j
Is there a way to deprecate a java method but only when used from Kotlin? And still consider usages from Java as non-deprecated?
h
what is the use case for this
j
For instance doing things like
Preconditions.assertNotNull()
is good practice in Java. But in Kotlin proper type nullability is better
therefore I'd like to see this method as deprecated from Kotlin code, but not from Java code.
h
why not write this code in kotlin
j
Because in kotlin this kind of assertion is not required, nor should be used. Nullability should be declared in the type when writing kotlin code.
h
when public kotlin methods are used with non null types, the byte code adds a check to make sure they are non null
j
yes and that the point
h
what’s wrong with that
j
I want to discourage the use of this method in Kotlin, since the Kotlin compiler already do everything
But I don't want to discourage its usage from Java where it is still necessary
a
you could probably write a lint check for that
👍 1