From 42cbee883fb07fdb05da80e5dc9119b8cef8cb8f Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Wed, 16 Nov 2011 04:20:46 +0000 Subject: [PATCH] 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 as opposed to Collection. After this change, AbstractCacheManager expects Collection throughout. --- .../springframework/cache/support/AbstractCacheManager.java | 4 ++-- .../springframework/cache/support/SimpleCacheManager.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/org.springframework.context/src/main/java/org/springframework/cache/support/AbstractCacheManager.java b/org.springframework.context/src/main/java/org/springframework/cache/support/AbstractCacheManager.java index e24fd746c0..95dfa7cc7a 100644 --- a/org.springframework.context/src/main/java/org/springframework/cache/support/AbstractCacheManager.java +++ b/org.springframework.context/src/main/java/org/springframework/cache/support/AbstractCacheManager.java @@ -44,7 +44,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing public void afterPropertiesSet() { - Collection caches = loadCaches(); + Collection 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 loadCaches(); + protected abstract Collection loadCaches(); } diff --git a/org.springframework.context/src/main/java/org/springframework/cache/support/SimpleCacheManager.java b/org.springframework.context/src/main/java/org/springframework/cache/support/SimpleCacheManager.java index 3350309cd8..007ba989cd 100644 --- a/org.springframework.context/src/main/java/org/springframework/cache/support/SimpleCacheManager.java +++ b/org.springframework.context/src/main/java/org/springframework/cache/support/SimpleCacheManager.java @@ -29,17 +29,17 @@ import org.springframework.cache.Cache; */ public class SimpleCacheManager extends AbstractCacheManager { - private Collection caches; + private Collection caches; /** * Specify the collection of Cache instances to use for this CacheManager. */ - public void setCaches(Collection caches) { + public void setCaches(Collection caches) { this.caches = caches; } @Override - protected Collection loadCaches() { + protected Collection loadCaches() { return this.caches; }