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 Generic<Integer,String,Double,Short,Float> setSampleField(Class<?> 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;
35 /*public String getSampleField() {
39 /*public void setSampleField(String sampleField) {
40 this.sampleField = sampleField;
43 public List<String> setSampleField(List<String> listString) {
48 public static void main(String[] args) {
50 /*Method[] methods = SampleClass.class.getMethods();
51 // Method[] methods = Class.class.getMethods();
53 for(Method meth : methods) {
54 if (meth.getName().equals("setSampleField")) {
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]);
63 System.out.println();*/
64 /*Type superCls = Generic.class.getGenericSuperclass();
65 //Type superCls = String.class.getGenericSuperclass();
66 System.out.println(superCls);
68 Type[] interfaces = Generic.class.getGenericInterfaces();
69 for (int i = 0; i < interfaces.length; i++) {
70 System.out.println(interfaces[i]);
73 Method[] methods = Class.class.getMethods();
75 for(Method mth : methods) {
76 if (mth.getName().equals("isAssignableFrom")) {
80 Type[] parameters = method.getGenericParameterTypes();
81 //Type[] parameters = methods[0].getGenericParameterTypes();
82 for (int i = 0; i < parameters.length; i++) {
83 System.out.println(parameters[i]);
86 /*Class[] parameterTypes = methods[0].getParameterTypes();
87 for(Class parameterType: parameterTypes){
88 System.out.println(parameterType.getName());
91 System.out.println();*/
92 /*TypeVariable[] typeParameters = Generic.class.getTypeParameters();
93 //TypeVariable[] typeParameters = SampleClass.class.getTypeParameters();
94 for(TypeVariable typeVar: typeParameters){
95 System.out.println(typeVar);
100 Type[] bounds = typeParameters[0].getBounds();
101 for (Type bound : bounds) {
102 System.out.println(bound);
104 System.out.println();
105 Type returnType = methods[0].getGenericReturnType();
106 System.out.println(returnType);