diff --git a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/TypeDefinitionBuilder.java b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/TypeDefinitionBuilder.java index 797d9f8a0e5..12c73e02a87 100755 --- a/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/TypeDefinitionBuilder.java +++ b/dubbo-metadata-report/dubbo-metadata-definition/src/main/java/org/apache/dubbo/metadata/definition/TypeDefinitionBuilder.java @@ -35,20 +35,18 @@ */ public class TypeDefinitionBuilder { - private static final ThreadLocal> builders; - - static { - builders = new ThreadLocal>(); - builders.set(new ArrayList()); - builders.get().add(new ArrayTypeBuilder()); - builders.get().add(new CollectionTypeBuilder()); - builders.get().add(new MapTypeBuilder()); - builders.get().add(new EnumTypeBuilder()); - } + private static final ThreadLocal> builders = ThreadLocal.withInitial(() -> { + ArrayList l = new ArrayList<>(); + l.add(new ArrayTypeBuilder()); + l.add(new CollectionTypeBuilder()); + l.add(new MapTypeBuilder()); + l.add(new EnumTypeBuilder()); + return l; + }); public static TypeDefinition build(Type type, Class clazz, Map, TypeDefinition> typeCache) { TypeBuilder builder = getGenericTypeBuilder(type, clazz); - TypeDefinition td = null; + TypeDefinition td; if (builder != null) { td = builder.build(type, clazz, typeCache); } else { @@ -66,14 +64,14 @@ private static TypeBuilder getGenericTypeBuilder(Type type, Class clazz) { return null; } - private Map, TypeDefinition> typeCache = new HashMap, TypeDefinition>(); + private Map, TypeDefinition> typeCache = new HashMap<>(); public TypeDefinition build(Type type, Class clazz) { return build(type, clazz, typeCache); } public List getTypeDefinitions() { - return new ArrayList(typeCache.values()); + return new ArrayList<>(typeCache.values()); } }