Here you can find the source of getGenericMultivalueType(final Field p)
Parameter | Description |
---|---|
p | Field to examine |
public static Class<?> getGenericMultivalueType(final Field p)
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.Map; public class Main { /**/*from w w w. ja v a2 s . c o m*/ * Returns the generic class of multi-value objects. * * @param p * Field to examine * @return The Class<?> of generic type if any, otherwise null */ public static Class<?> getGenericMultivalueType(final Field p) { if (p.getType() instanceof Class<?>) { final Type genericType = p.getGenericType(); if (genericType != null && genericType instanceof ParameterizedType) { final ParameterizedType pt = (ParameterizedType) genericType; if (pt.getActualTypeArguments() != null && pt.getActualTypeArguments().length > 0) { if (((Class<?>) pt.getRawType()) .isAssignableFrom(Map.class)) { if (pt.getActualTypeArguments()[1] instanceof Class<?>) { return (Class<?>) pt.getActualTypeArguments()[1]; } else if (pt.getActualTypeArguments()[1] instanceof ParameterizedType) return (Class<?>) ((ParameterizedType) pt .getActualTypeArguments()[1]) .getRawType(); } else if (pt.getActualTypeArguments()[0] instanceof Class<?>) { return (Class<?>) pt.getActualTypeArguments()[0]; } else if (pt.getActualTypeArguments()[0] instanceof ParameterizedType) return (Class<?>) ((ParameterizedType) pt .getActualTypeArguments()[0]).getRawType(); } } else if (p.getType().isArray()) return p.getType().getComponentType(); } return null; } }