Skip to content

Commit d1b873c

Browse files
committed
#1010 commit
1 parent 870e364 commit d1b873c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

note/剑指offer-java-pdf.pdf

269 KB
Binary file not shown.

src/com/blankj/study/temp/Test14.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.blankj.study.temp;
2+
3+
import java.lang.reflect.InvocationTargetException;
4+
import java.lang.reflect.Method;
5+
import java.util.ArrayList;
6+
import java.util.List;
7+
8+
/**
9+
* LIst<Integer>中保存String类型
10+
*/
11+
public class Test14 {
12+
public static void main(String[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
13+
List<Integer> list = new ArrayList<>();
14+
for (int i = 1; i <= 3; i++) {
15+
list.add(i);
16+
}
17+
18+
// https://blog.csdn.net/sulaymanyf/article/details/82228527
19+
/*Method[] methods = list.getClass().getMethods();
20+
for (Method method : methods) {
21+
if("add".equals(method.getName())){
22+
method.invoke(list,"字符串1");
23+
}
24+
}*/
25+
26+
Method m = list.getClass().getDeclaredMethod("add", Object.class);
27+
m.invoke(list, "字符串2");
28+
29+
30+
System.out.println(list.toString());
31+
}
32+
}

0 commit comments

Comments
 (0)