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