Java 为什么 Guava 的 EventBus 在 IntelliJ 2018.2 中被标记为不稳定?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51926704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:18:20  来源:igfitidea点击:

Why is Guava's EventBus marked unstable in IntelliJ 2018.2?

javaintellij-idea

提问by 20knots

A new inspection was added in IntelliJ 2018.2 which should warn from unstable APIs: https://youtrack.jetbrains.com/issue/IDEA-159541.

IntelliJ 2018.2 中添加了一项新检查,应警告不稳定的 API:https://youtrack.jetbrains.com/issue/IDEA-159541 。

This warning shows up for the Guava's EventBus. Why is this an unstable API?

这个警告出现在 Guava 的 EventBus 上。为什么这是一个不稳定的 API?

采纳答案by JB Nizet

Because the EventBusclassis annotated as @Beta.

因为EventBus被注释为@Beta

You'd have to ask the Guava project maintainerswhy a class that exists for 16 versions of Guava is still Beta, but it still is.

您必须询问 Guava 项目维护人员,为什么存在 16 个 Guava 版本的类仍然是 Beta,但它仍然是 Beta。

回答by Hiery Nomus

EventBus class is marked with the @com.google.common.annotations.Betaannotation. So I think the inspection is triggering on that. See: https://google.github.io/guava/releases/22.0/api/docs/com/google/common/eventbus/EventBus.html

EventBus 类用@com.google.common.annotations.Beta注解标记。所以我认为检查是由此触发的。请参阅:https: //google.github.io/guava/releases/22.0/api/docs/com/google/common/eventbus/EventBus.html

回答by Frankie

Besides @JB Nizet's answer that perfectly explains why IntelliJ flags this error, you may also want to suppress itglobally but only for the Google Beta annotations.

除了@JB Nizet 的回答完美地解释了 IntelliJ 标记此错误的原因之外,您可能还想在全局范围内抑制它,但仅针对 Google Beta annotations

Just go to Settings -> Inspections -> JVM languagesas per the picture bellow and, if you feel like it, delete the com.google.common.anotations.Beta.

只需Settings -> Inspections -> JVM languages按照下面的图片转到,如果您愿意,请删除com.google.common.anotations.Beta.

how to disable IntelliJ's Google Beta annotation

how to disable IntelliJ's Google Beta annotation

回答by BullyWiiPlaza

You can also ask IntelliJto suppress the warning for the definition of your @Betaannotated class as follows:

您还可以要求IntelliJ取消@Beta注释类定义的警告,如下所示:

@SuppressWarnings("UnstableApiUsage")
static RateLimiter API_RATE_LIMITER = RateLimiter.create(8);

This properly deals with the warning in a particular case when you're okay with using the class anyway (and don't run into issues).

当您无论如何都可以使用该类时(并且不会遇到问题),这可以正确处理特定情况下的警告。

回答by MiguelMunoz

Maybe a better question is why is the @Subscribed annotation marked @Beta? It's been around for a long time, and it doesn't seem like they may get rid of it any time soon, especially since a lot of people must be using it already.

也许更好的问题是为什么@Subscribed 注释标记为@Beta?它已经存在很长时间了,而且他们似乎不会很快摆脱它,尤其是因为很多人肯定已经在使用它了。