java - 在 Java 中实例化 BiMap 的 google-collections

标签 java guava bimap

如何实例化 Bimap谷歌 Collection ?

我已阅读问题 Java: Instantiate Google Collection's HashBiMap

我的代码示例

import com.google.common.collect.BiMap;

public class UserSettings {

 private Map<String, Integer> wordToWordID;

 UserSettings() {

  this.wordToWordID = new BiMap<String. Integer>();

我得到 cannot instantiate the type BiMap<String, Integer> .

最佳答案

如链接问题中所述,您应该使用 create() 工厂方法。

在你的情况下,这意味着改变

this.wordToWordID = new BiMap<String. Integer>();

this.wordToWordID = HashBiMap.create(); 

关于java - 在 Java 中实例化 BiMap 的 google-collections,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2428955/

相关文章:

java - 我们有 MultiBiMap 吗?

templates - 模板中标记为 boost::bimap - 它们有效吗?

java - SortedSet 上的 Guava Joiner

java - 如何将 Guava 添加到 Eclipse 项目

java - 无效的 XML 字符 (Unicode : 0x3) was found on unmarshalling after successful marshalling

java - 来自 Java 的 Redis 基准测试

java - Google Guava 缓存默认过期

java - 编写双向映射时如何绕过 "Erasure of method is the same as another method"

java - 如何去掉句子中的中缀?

java - 使用 Java Stream API 对嵌套列表求和