Add generics to AbstractCacheManager#caches

Facilitates type-safe programmatic configuration from @Bean methods:

    @Bean
    public CacheManager cacheManager() {
        SimpleCacheManager cm = new SimpleCacheManager();
        cm.setCaches(Arrays.asList(
            new ConcurrentMapCache("default"),
            new ConcurrentMapCache("primary"),
            new ConcurrentMapCache("secondary")
        ));
        return cm;
    }

Prior to this change, the code above would have raised errors on the
Arrays.asList() call because it returns a Collection<? extends Cache>
as opposed to Collection<Cache>.

After this change, AbstractCacheManager expects
Collection<? extends Cache> throughout.
This commit is contained in:
Chris Beams
2011-11-16 04:20:46 +00:00
parent 7a71af2989
commit 42cbee883f
2 changed files with 5 additions and 5 deletions

View File

@@ -44,7 +44,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing
public void afterPropertiesSet() {
Collection<Cache> caches = loadCaches();
Collection<? extends Cache> caches = loadCaches();
Assert.notEmpty(caches, "loadCaches must not return an empty Collection");
this.cacheMap.clear();
@@ -73,6 +73,6 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing
* Load the caches for this cache manager. Occurs at startup.
* The returned collection must not be null.
*/
protected abstract Collection<Cache> loadCaches();
protected abstract Collection<? extends Cache> loadCaches();
}

View File

@@ -29,17 +29,17 @@ import org.springframework.cache.Cache;
*/
public class SimpleCacheManager extends AbstractCacheManager {
private Collection<Cache> caches;
private Collection<? extends Cache> caches;
/**
* Specify the collection of Cache instances to use for this CacheManager.
*/
public void setCaches(Collection<Cache> caches) {
public void setCaches(Collection<? extends Cache> caches) {
this.caches = caches;
}
@Override
protected Collection<Cache> loadCaches() {
protected Collection<? extends Cache> loadCaches() {
return this.caches;
}