Working with Guava library. I want to override(to add some validation) the getOrDefault method of HashBiMap implementation. Looking into it, HashBiMap class is declared as final, I can't extend it. Any idea?
@GwtCompatible(emulated = true)
public final class HashBiMap<K, V> extends IteratorBasedAbstractMap<K, V>
implements BiMap<K, V>, Serializable {
....
}
Create a decorator around your
HashBiMapto validate.Guava popularized the
Forwarding*helper classes concept to simplify the decorator pattern of most collection types.But for some reason, the authors haven't provided us with a
ForwardingBiMapyet. So I would create (a basic) one myself or wait for the issue about the missingForwardingBiMapto be resolved. If you want to create your own, just do the following:Then implement your validation:
And then finally use it: