Skip to content

Commit 3996d50

Browse files
committed
Fix #1617 支持泛型对象嵌套
1 parent c425ef4 commit 3996d50

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/org/nutz/lang/Mirror.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1708,6 +1708,7 @@ public static Class<?>[] getGenericTypes(Field f) {
17081708
Matcher m = PTN.matcher(gts);
17091709
if (m.find()) {
17101710
String s = m.group(2);
1711+
s = s.replaceAll("<+.*?>+", "");
17111712
String[] ss = Strings.splitIgnoreBlank(s);
17121713
if (ss.length > 0) {
17131714
Class<?>[] re = new Class<?>[ss.length];

test/org/nutz/lang/MirrorTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ class Abcc {
501501

502502
List<?> list2;
503503

504+
List<Map<String, String>> list3;
505+
506+
Map<String, List<Map<String, ?>>> map3;
504507
}
505508

506509
@Test
@@ -530,6 +533,14 @@ public void test_getGenericTypes() throws Exception {
530533
f = Abcc.class.getDeclaredField("name");
531534
types = Mirror.getGenericTypes(f);
532535
assertEquals(0, types.length);
536+
537+
f = Abcc.class.getDeclaredField("list3");
538+
types = Mirror.getGenericTypes(f);
539+
assertEquals(1, types.length);
540+
541+
f = Abcc.class.getDeclaredField("map3");
542+
types = Mirror.getGenericTypes(f);
543+
assertEquals(2, types.length);
533544
}
534545

535546
public static class TBOC {

0 commit comments

Comments
 (0)