-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterfaceUseTest.java
More file actions
54 lines (43 loc) · 1.28 KB
/
Copy pathInterfaceUseTest.java
File metadata and controls
54 lines (43 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package Hello;
import java.lang.reflect.Method;
/**
* Created by yourfinger on 16/1/20.
*/
public class InterfaceUseTest {
public static void main(String[] args){
System.out.println("generic interface test..");
TestInterface<String> t1 = new ClassImpl1();
t1.test("baba");
for (Method method:
t1.getClass().getMethods()) {
if (method.getName() == "test"){
String parameterName = method.getParameterTypes()[0].getName();
System.out.println("Method name is " + parameterName);
}
}
TestInterface<String> t2 = new ClassImpl2<String>();
t2.test("baba");
for (Method method:
t2.getClass().getMethods()) {
if (method.getName() == "test"){
String parameterName = method.getParameterTypes()[0].getName();
System.out.println("Method name is " + parameterName);
}
}
}
}
interface TestInterface<T>{
void test(T t);
}
class ClassImpl1 implements TestInterface<String>{
@Override
public void test(String s) {
System.out.println(s);
}
}
class ClassImpl2<T> implements TestInterface<T>{
@Override
public void test(T t) {
System.out.println(t);
}
}