使用Kotlin时删除导入,@DepRecated&quot'注解

发布于 2025-02-10 09:43:14 字数 654 浏览 2 评论 0原文

我有一个自定义函数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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

躲猫猫 2025-02-17 09:43:14

如果这全是一个开放项目,则可以重构 - 将更新功能(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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文