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:
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user