如何在@resterrictto注释中使用多个范围

发布于 2025-01-31 13:53:33 字数 613 浏览 0 评论 0原文

我正在使用@RESTRICTTO注释来表示仅在子类或测试中应使用函数。

为此,我使用以下语法:

    @RestrictTo(value = [SUBCLASSES, TESTS])
    public override fun onCleared() {
        // Expose protected fun onCleared for tests
    }

起初它似乎在起作用,但我的队友报告了Android Studio显示了此警告:

“

我可以在再次构建项目后重现此项目。

如果我从注释中删除测试范围,就消失了,就好像注释不支持值中的多个范围一样。

您认为这是注释的预期行为吗?

您能想到另一种将功能限制在两个不同范围的联合的方法吗?

提前致谢

I'm using @RestrictTo annotation to denote that a function should be used in only in subclasses or tests.

To do that I use the following syntax:

    @RestrictTo(value = [SUBCLASSES, TESTS])
    public override fun onCleared() {
        // Expose protected fun onCleared for tests
    }

At first it seemed to be working but my teammates reported Android Studio showing this warning:

error-screen-shot

I could reproduce this after building the project again.

This error goes away if I remove the TESTS scope from the annotation as if the annotation does not support multiple scopes in values.

Do you think if this is the intended behavior of the annotation?

Can you think another way to restrict a function to the union of two different scopes?

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文