巧秒设计方法,不返回null

	/**
	 * {@inheritDoc}
	 * 
	 *  This implementation always returns a {@link Cache} implementation that will not
	 *  store items. Additionally, the request cache will be remembered by the manager for consistency.
	 */
	public Cache getCache(String name) {
		Cache cache = caches.get(name);
		if (cache == null) {
			caches.putIfAbsent(name, new NoOpCache(name));
			synchronized (names) {
				names.add(name);
			}
		}

		return caches.get(name);
	}

这是Spring的一个方法,很简单,绕过null

猜你喜欢

转载自a123159521.iteye.com/blog/1630261