使用Kotlin时删除导入,@DepRecated&quot'注解
我有一个自定义函数mutableStateFlow.update()
,我想将其弃用以支持官方的“ kotlinx.coroutines.flow.update”版本。
@Deprecated(
message = "This is not thread safe. Use the official version from kotlinx.coroutines.flow.update",
ReplaceWith("update(transformation)", "kotlinx.coroutines.flow.update"),
DeprecationLevel.ERROR
)
public inline fun <T> MutableStateFlow<T>.update(transformation: (previousValue: T) -> T) {
value = transformation(value)
}
这可以正常工作: 主要问题是旧的&amp;新的乐趣是相同的,因此IDE会感到困惑,因为两者都是导入的。 因此,当调用replacewith
时,我需要删除我旧版本的导入。这可能吗? (是否有更好的选择?)
如果它很重要:我们主要与Android Studio合作
I have a custom function MutableStateFlow.update()
, which i want to deprecate in favor of the official "kotlinx.coroutines.flow.update" version.
@Deprecated(
message = "This is not thread safe. Use the official version from kotlinx.coroutines.flow.update",
ReplaceWith("update(transformation)", "kotlinx.coroutines.flow.update"),
DeprecationLevel.ERROR
)
public inline fun <T> MutableStateFlow<T>.update(transformation: (previousValue: T) -> T) {
value = transformation(value)
}
This works ok-ish:
The main issue is that the signature of the old & the new fun are the same, so the IDE gets confused which to choose, since both are imported.
I therefore need to remove the import for my old version when the ReplaceWith
is called. Is this possible? (Is there a better alternative?)
In case it matters: We're working mainly with Android Studio
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果这全是一个开放项目,则可以重构 - 将更新功能(Shift + F6)重命名为某些唯一名称。那么就不会发生进口冲突。
If this is all in one open project, you could Refactor->Rename your update function (Shift + F6) to some unique name. Then there won't be the import conflict.