Hi there :slightly_smiling_face: Do you guys know ...
# announcements
s
Hi there 🙂 Do you guys know how to deprecate stuff that is not easily replaceable with another line of code? I am cleaning up a legacy app and there are a few constructs that I want to phase out. Example: Lets say I have an app where the old way of accessing the database is done via type-unsafe results like
Array<Any?>
. There are helper methods that type juggle the return values like so:
fun Any?.toIntOrZero(): Int = (this as? Long)?.toInt() ?: (this as? Double)?.toInt() ?: 0
This is of course horrible, so I want to deprecate all of these helper functions, so that any developer sees that this is not the right way to do things:
Copy code
@Deprecated("use the new type safe db repository instead of this manual type-juggling (see readme.md for refactoring advice)")
fun Any?.toIntOrZero(): Int = (this as? Long)?.toInt() ?: (this as? Double)?.toInt() ?: 0
But now there is a warning, that the replaceWith parameter of the deprecation annotation is missing. But there is no simple replacement of this, since every database access needs to be refactored and cleaned up individually. this helper function is just a symptom of the problem, so to speak. So is this ok, just to slap a
@Suppress("DeprecatedCallableAddReplaceWith")
in front of this deprecation annotation and call it a day? Or is there a better way to do this?
i
You can safely ignore this IDE suggestion. Perhaps you can also stop it by converting the function to have a block body.
s
The warning is still present with block body
Perhaps Deprecated needs an option to mark that migration must be handled manually and its not simply "missing".
s
that would be helpful, in my case at least. I was not sure, if deprecating these "symptom functions" is the right way to do this, but they really should be deprecated. Because every time they are used, the developer does something wrong ^^