Search code examples
javaguavabimap

To instantiate BiMap Of google-collections in Java


How can you instantiate a Bimap of Google-collections?

I've read the question Java: Instantiate Google Collection's HashBiMap

A sample of my code

import com.google.common.collect.BiMap;

public class UserSettings {

 private Map<String, Integer> wordToWordID;

 UserSettings() {

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

I get cannot instantiate the type BiMap<String, Integer>.


Solution

  • As stated in the linked question, you are supposed to use the create() factory methods.

    In your case, this means changing

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

    to

    this.wordToWordID = HashBiMap.create();