-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstraitUseTest.java
More file actions
43 lines (34 loc) · 883 Bytes
/
Copy pathConstraitUseTest.java
File metadata and controls
43 lines (34 loc) · 883 Bytes
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
package Hello;
import java.lang.reflect.Method;
/**
* Created by yourfinger on 16/1/20.
*/
public class ConstraitUseTest {
public static void main(String[] args){
System.out.println("bound type parameters test..");
Base<Dog> base = new Child();
base.test(new Dog());
for (Method method:
base.getClass().getMethods()) {
if (method.getName() == "test"){
String parameterName = method.getParameterTypes()[0].getName();
System.out.println("parameterName is " + parameterName);
}
}
}
}
class Pet{
}
class Dog extends Pet{
}
class Base<T extends Pet>{
public void test(T t){
System.out.println("Base : " + t);
}
}
class Child extends Base<Dog>{
@Override
public void test(Dog dog) {
System.out.println("child : " + dog);
}
}