GMoney
GMoney

Reputation: 205

Guava LoadingCache getAll - but without any arguments?

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?

Upvotes: 3

Views: 4021

Answers (1)

Louis Wasserman
Louis Wasserman

Reputation: 198581

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.

Upvotes: 4

Related Questions