1 import java.lang.reflect.Method;
2 import java.lang.reflect.Type;
3 import java.lang.reflect.TypeVariable;
4 import java.io.Serializable;
8 import java.util.ArrayList;
9 import java.util.Arrays;
11 public class Reflection {
13 interface GenericSuperShort<XYZ> {
17 class GenericShort<TUVW,ABCD> {
20 class Generic<TUVW,ABCD,KLM,NOP,XYZ> extends GenericShort<TUVW,ABCD> implements GenericSuperShort<XYZ>, Serializable {
24 class SampleClass<VWXZ> {
25 private String sampleField;
27 public Class<?> setSampleField(Class<?> clazz,
28 List<String> listString, Map<Integer,String> mapString,
29 Generic<Integer,String,Double,Short,Float> test,
30 String sampleField, int one, short two, double three, Object obj) {
32 this.sampleField = sampleField;
37 /*public String getSampleField() {
41 /*public void setSampleField(String sampleField) {
42 this.sampleField = sampleField;
45 public List<String> setSampleField(List<String> listString) {
50 public static void main(String[] args) {
52 /*Method[] methods = SampleClass.class.getMethods();
53 // Method[] methods = Class.class.getMethods();
55 for(Method meth : methods) {
56 if (meth.getName().equals("setSampleField")) {
60 Type[] parameters = method.getGenericParameterTypes();
61 //Type[] parameters = methods[0].getGenericParameterTypes();
62 for (int i = 0; i < parameters.length; i++) {
63 System.out.println(parameters[i]);
65 System.out.println();*/
66 /*Type superCls = Generic.class.getGenericSuperclass();
67 //Type superCls = String.class.getGenericSuperclass();
68 System.out.println(superCls);
70 Type[] interfaces = Generic.class.getGenericInterfaces();
71 for (int i = 0; i < interfaces.length; i++) {
72 System.out.println(interfaces[i]);
75 Method[] methods = SampleClass.class.getMethods();
77 for(Method mth : methods) {
78 if (mth.getName().equals("setSampleField")) {
82 Type[] parameters = method.getGenericParameterTypes();
83 //Type[] parameters = methods[0].getGenericParameterTypes();
84 for (int i = 0; i < parameters.length; i++) {
85 System.out.println(parameters[i]);
88 /*Class[] parameterTypes = methods[0].getParameterTypes();
89 for(Class parameterType: parameterTypes){
90 System.out.println(parameterType.getName());
93 System.out.println();*/
94 /*TypeVariable[] typeParameters = Generic.class.getTypeParameters();
95 //TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
96 for(TypeVariable typeVar: typeParameters){
97 System.out.println(typeVar);
100 System.out.println();
102 Type[] bounds = typeParameters[0].getBounds();
103 for (Type bound : bounds) {
104 System.out.println(bound);
106 System.out.println();*/
107 Type returnType = method.getGenericReturnType();
108 System.out.println(returnType);