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>
.
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();
BiMap is an interface, and as such cannot be instantiated. You need to instantiate a concrete subclass according to the properties you want, available subclasses (according to the javadoc) are EnumBiMap, EnumHashBiMap, HashBiMap, ImmutableBiMap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With