Domanda

I am using Guava LoadingCache to bulk load all elements at once into my eager cache. But the implementation of the loadAll method that I'm supplying does not really need an Iterable<? extends K> keys argument, since my DAO does not except any parameters either - my DAO method returns generic Map<K,V>.

Since my implementation is generic, I'm using generics to do a call on getAllIterable(<? extends K> keys_), but because of the type erasure, I can not instantiate K key, and pass it to getAll, since it does not expect any non null keys.

Does anyone know of any workaround around this?

È stato utile?

Soluzione

If the goal is just to prepopulate a Cache with the contents of a Map<K, V>, then you should just use Cache.putAll(Map<K, V>) to put all the entries from a specified Map in the cache.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top