Browse Source

缩减代码

James 2 years ago
parent
commit
82151d7fe1
1 changed files with 8 additions and 15 deletions
  1. 8 15
      src/main/java/com/jfinal/template/expr/ast/FastFieldGetter.java

+ 8 - 15
src/main/java/com/jfinal/template/expr/ast/FastFieldGetter.java

@@ -59,22 +59,15 @@ public class FastFieldGetter extends FieldGetter {
 		for (java.lang.reflect.Method method : methodArray) {
 		for (java.lang.reflect.Method method : methodArray) {
 			if (method.getName().equals(getterName) && method.getParameterCount() == 0) {
 			if (method.getName().equals(getterName) && method.getParameterCount() == 0) {
 
 
-				Proxy proxy = cache.get(targetClass);
-				if (proxy == null) {
-					synchronized (targetClass) {
-						proxy = cache.get(targetClass);
-						if (proxy == null) {
-							try {
-								proxy = createProxy(targetClass, fieldName);
-							} catch (Throwable e) {
-								return null;
-							}
-							cache.putIfAbsent(targetClass, proxy);
-						}
+				Proxy proxy = cache.computeIfAbsent(targetClass, key -> {
+					try {
+						return createProxy(key, fieldName);
+					} catch (Throwable e) {
+						return null;
 					}
 					}
-				}
-
-				return new FastFieldGetter(proxy, method);
+				});
+				return proxy != null ? new FastFieldGetter(proxy, method) : null;
+				
 			}
 			}
 		}
 		}