diff --git a/src/main/java/io/github/xxyopen/novel/core/config/CacheConfig.java b/src/main/java/io/github/xxyopen/novel/core/config/CacheConfig.java index 8a13fbe..5493a94 100644 --- a/src/main/java/io/github/xxyopen/novel/core/config/CacheConfig.java +++ b/src/main/java/io/github/xxyopen/novel/core/config/CacheConfig.java @@ -37,7 +37,8 @@ public class CacheConfig { SimpleCacheManager cacheManager = new SimpleCacheManager(); List caches = new ArrayList<>(CacheConsts.CacheEnum.values().length); - for (CacheConsts.CacheEnum c : CacheConsts.CacheEnum.values()) { + // 类型推断 var 非常适合 for 循环,JDK 10 引入,JDK 11 改进 + for (var c : CacheConsts.CacheEnum.values()) { if (c.isLocal()) { Caffeine caffeine = Caffeine.newBuilder().recordStats().maximumSize(c.getMaxSize()); if (c.getTtl() > 0) { @@ -62,7 +63,8 @@ public class CacheConfig { .disableCachingNullValues().prefixCacheNameWith(CacheConsts.REDIS_CACHE_PREFIX); Map cacheMap = new LinkedHashMap<>(CacheConsts.CacheEnum.values().length); - for (CacheConsts.CacheEnum c : CacheConsts.CacheEnum.values()) { + // 类型推断 var 非常适合 for 循环,JDK 10 引入,JDK 11 改进 + for (var c : CacheConsts.CacheEnum.values()) { if (c.isRemote()) { if (c.getTtl() > 0) { cacheMap.put(c.getName(), RedisCacheConfiguration.defaultCacheConfig().disableCachingNullValues() diff --git a/src/main/java/io/github/xxyopen/novel/service/impl/EsSearchServiceImpl.java b/src/main/java/io/github/xxyopen/novel/service/impl/EsSearchServiceImpl.java index d977947..271c94f 100644 --- a/src/main/java/io/github/xxyopen/novel/service/impl/EsSearchServiceImpl.java +++ b/src/main/java/io/github/xxyopen/novel/service/impl/EsSearchServiceImpl.java @@ -77,7 +77,8 @@ public class EsSearchServiceImpl implements SearchService { List list = new ArrayList<>(); List> hits = response.hits().hits(); - for (Hit hit : hits) { + // 类型推断 var 非常适合 for 循环,JDK 10 引入,JDK 11 改进 + for (var hit : hits) { EsBookDto book = hit.source(); assert book != null; if (!CollectionUtils.isEmpty(hit.highlight().get(EsConsts.BookIndex.FIELD_BOOK_NAME))) {