Adding ParameterizedTypeImpl to the getGenericInterfaces method.
[jpf-core.git] / examples / Reflection.java
1 import java.lang.reflect.Method;
2 import java.lang.reflect.Type;
3 import java.lang.reflect.TypeVariable;
4 import java.io.Serializable;
5
6 import java.util.List;
7 import java.util.Map;
8 import java.util.ArrayList;
9 import java.util.Arrays;
10
11 public class Reflection {
12
13     interface GenericSuperShort<XYZ> {
14
15     }
16
17     class GenericShort<TUVW,ABCD> {
18     }
19
20     class Generic<TUVW,ABCD,KLM,NOP,XYZ> extends GenericShort<TUVW,ABCD> implements GenericSuperShort<XYZ>, Serializable {
21
22     }
23
24     class SampleClass<VWXZ> {
25         private String sampleField;
26
27         public Generic<Integer,String,Double,Short,Float> setSampleField(Class<VWXZ> clazz, List<String> listString, Map<Integer,String> mapString,
28                                                                          Generic<Integer,String,Double,Short,Float> test,
29                                                                          String sampleField, int one, short two, double three, Object obj) {
30             this.sampleField = sampleField;
31             return test;
32         }
33            
34            
35            /*public String getSampleField() {
36                   return sampleField;
37            }*/
38            
39            /*public void setSampleField(String sampleField) {
40               this.sampleField = sampleField;
41            }
42            
43            public List<String> setSampleField(List<String> listString) {
44                   return listString;
45            }*/
46         }
47
48    public static void main(String[] args) {
49
50       /*Method[] methods = SampleClass.class.getMethods();
51       //  Method[] methods = Class.class.getMethods();
52         Method method = null;
53         for(Method meth : methods) {
54             if (meth.getName().equals("setSampleField")) {
55                 method = meth;
56             }
57         }
58         Type[] parameters = method.getGenericParameterTypes();
59       //Type[] parameters = methods[0].getGenericParameterTypes();
60       for (int i = 0; i < parameters.length; i++) {
61          System.out.println(parameters[i]);
62       }
63       System.out.println();*/
64       Type superCls = Generic.class.getGenericSuperclass();
65       //Type superCls = String.class.getGenericSuperclass();
66       System.out.println(superCls);
67         System.out.println();
68         Type[] interfaces = Generic.class.getGenericInterfaces();
69         for (int i = 0; i < interfaces.length; i++) {
70             System.out.println(interfaces[i]);
71         }
72       /*Class[] parameterTypes = methods[0].getParameterTypes();
73       for(Class parameterType: parameterTypes){
74          System.out.println(parameterType.getName());   
75  
76       }
77       System.out.println();*/
78       /*TypeVariable[] typeParameters = Generic.class.getTypeParameters();
79       //TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
80       for(TypeVariable typeVar: typeParameters){
81          System.out.println(typeVar);   
82  
83       }
84       System.out.println();
85
86       Type[] bounds = typeParameters[0].getBounds();
87       for (Type bound : bounds) {
88           System.out.println(bound);
89       }
90       System.out.println();
91       Type returnType = methods[0].getGenericReturnType();
92       System.out.println(returnType);
93           */
94    }
95 }
96