如何在IntelliJ中禁用"可选用作字段或参数类型"警告?

And*_*rey 17 java intellij-idea

Jetbrains最近决定java.util.Optional(以及Guava的com.google.common.base.Optional)不应该用作字段或参数类型...谢谢,但不,谢谢......这个警告怎么样被禁用?

作为旁注:触发针对Optional的这种特定用法的警告似乎完全没有道理......

And*_*rey 19

从IntelliJ的首选项/设置:

  1. 选择Editor>Inspections
  2. 展开Java>Abstraction issues
  3. 取消选中 'Optional' used as field or parameter type

  • 如果这个问题在这里重新开放将是我的回答是:'@SuppressWarnings("OptionalUsedAsFieldOrParameterType")`见https://github.com/JetBrains/intellij-community/blob/master/plugins/InspectionGadgets/src/inspectionDescriptions/OptionalUsedAsFieldOrParameterType.html (34认同)
  • @KarlthePagan 根据 /sf/answers/2800371521/ 上的提示,您通常可以在 IntelliJ 的 [InspectionDescriptions](https://github.com/JetBrains/intellij-community) 中搜索检查文本/tree/master/plugins/InspectionGadgets/src/inspectionDescriptions) git 目录以查找与 `@SuppressWarnings` 一起使用的值。 (3认同)