Source Code : Get Parameterized Type
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Get Parameterized Type
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
public abstract class ClassUtils {
static public ParameterizedType getParameterizedType(Class<?> target) {
Type[] types = getGenericType(target);
if (types.length > 0 && types[0] instanceof ParameterizedType) {
return (ParameterizedType) types[0];
}
return null;
}
static public Type[] getParameterizedTypes(Class<?> target) {
Type[] types = getGenericType(target);
if (types.length > 0 && types[0] instanceof ParameterizedType) {
return ((ParameterizedType) types[0]).getActualTypeArguments();
}
return null;
}
static public Type[] getGenericType(Class<?> target) {
if (target == null)
return new Type[0];
Type[] types = target.getGenericInterfaces();
if (types.length > 0) {
return types;
}
Type type = target.getGenericSuperclass();
if (type != null) {
if (type instanceof ParameterizedType) {
return new Type[] { type };
}
}
return new Type[0];
}
}
Thank with us