java.util.Collections
字段的用法: EMPTY_LIST
、EMPTY_MAP
或 EMPTY_SET
。 这些字段用法可以替换为以下方法调用: emptyList()
、emptyMap()
或 emptySet()
。
这样的方法调用防止编译器发出未经检查的警告,因为可以推断出类型参数。
示例:
List<Integer> emptyList = Collections.EMPTY_LIST;
在应用快速修复后:
List<Integer> emptyList = Collections.emptyList();
此检查仅在项目或模块的语言级别为 5 级或更高级别时有效。