Java Reflection Generic Type getGenericType(Method setter)

Here you can find the source of getGenericType(Method setter)

Description

get Generic Type

License

Apache License

Declaration

private static Class<?> getGenericType(Method setter) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

public class Main {
    private static Class<?> getGenericType(Method setter) {
        if (setter != null) {
            Type[] genericParameterTypes = setter.getGenericParameterTypes();
            for (int i = 0; i < genericParameterTypes.length; i++) {
                if (genericParameterTypes[i] instanceof ParameterizedType) {
                    Type[] parameters = ((ParameterizedType) genericParameterTypes[i]).getActualTypeArguments();
                    if (parameters != null && parameters.length == 1) {
                        return (Class<?>) parameters[0];
                    }//from  ww  w . j  a v a2  s . co  m
                }
            }
        }
        return null;
    }
}

Related

  1. getGenerics(Type t)
  2. getGenericString(AccessibleObject ao)
  3. getGenericSuperType(Type t)
  4. getGenericType(@Nullable Type genericType)
  5. getGenericType(Member member, int index)
  6. getGenericType(Object target)
  7. getGenericType(Type genType, int index)
  8. getGenericType(Type t, int index)
  9. getGenericType(Type type)