Skip to content

Commit f61b490

Browse files
committed
improved typereference support.
1 parent c1ef315 commit f61b490

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

src/main/java/com/alibaba/fastjson/TypeReference.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@ protected TypeReference(){
3434

3535
Type oriType = ((ParameterizedType) superClass).getActualTypeArguments()[0];
3636

37-
//修复在安卓环境中问题
38-
Type cachedType = classTypeCache.get(oriType);
39-
if (cachedType == null) {
40-
classTypeCache.putIfAbsent(oriType, oriType);
41-
cachedType = classTypeCache.get(oriType);
42-
}
37+
if (oriType instanceof Class) {
38+
type = oriType;
39+
} else {
40+
//修复在安卓环境中问题
41+
Type cachedType = classTypeCache.get(oriType);
42+
if (cachedType == null) {
43+
classTypeCache.putIfAbsent(oriType, oriType);
44+
cachedType = classTypeCache.get(oriType);
45+
}
4346

44-
type = cachedType;
47+
type = cachedType;
48+
}
4549
}
4650

4751
/**
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.alibaba.json.bvt;
2+
3+
import com.alibaba.fastjson.TypeReference;
4+
import junit.framework.TestCase;
5+
6+
import java.lang.reflect.Type;
7+
8+
/**
9+
* Created by wenshao on 01/07/2017.
10+
*/
11+
public class TypeReferenceTest13 extends TestCase {
12+
public void test_typeRef() throws Exception {
13+
Type type = new TypeReference<Integer>(){}.getType();
14+
assertSame(Integer.class, type);
15+
}
16+
17+
public <T> void test_typeRef_1() throws Exception {
18+
Type type1 = new TypeReference<T>(){}.getType();
19+
Type type2 = new TypeReference<T>(){}.getType();
20+
assertSame(type1, type2);
21+
}
22+
}

0 commit comments

Comments
 (0)