[英]Java cannot resolve symbol 'Maps'
我正在尝试使用 java 中的 gson 和 guava 库来获取两个 JSON 文件之间的差异。
我收到错误消息:“无法解析符号‘地图’。我的 InteliJ 安装文件夹中的 lib 文件夹中有番石榴库 jar 文件,pom.xml 文件中的依赖项如下所示:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0.1-jre</version>
</dependency>
创建 diff 的函数如下所示
public static Map<String, Object> newCompare(JsonElement original, JsonElement output){
Type type = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> leftMap = gson.fromJson(original, type);
Map<String, Object> rightMap = gson.fromJson(output, type);
return Maps.Difference(leftMap, rightMap);
}
我尝试重新导入所有 maven 项目并寻找答案,但我找到的所有解决方案都与 android 地图有关。 你能给我一些关于如何解决这个问题的建议,或者提出任何其他解决方案吗? 非常感谢。
首先,它是 Google Guava 中的Maps::difference
,而不是Maps::Difference
(通常,我们从不使用PascalCase作为 Java 中的方法名称;而驼峰命名是最好的约定)。
其次,根据您的评论,我已经通过相同的依赖重现了您的问题:
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.0.1-jre</version>
</dependency>
和进口
import com.google.common.collect.Maps;
之后,
Map<String, String> map1 = new HashMap<>();
Map<String, String> map2 = new HashMap<>();
Maps.difference(map1, map2);
工作得很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.