码迷,mamicode.com
首页 > 其他好文 > 详细

ParameterizedType

时间:2020-07-16 11:48:00      阅读:52      评论:0      收藏:0      [点我收藏+]

标签:eva   int   oid   dex   entry   ict   ram   end   map   

 

   private static class ParameterizedTypeTest<T extends Number> {
        private List<T> list = null;

        public static void main(String[] args) throws NoSuchFieldException {
            testTypeVariable();
        }

        private Map.Entry<String, Integer> map = null;

        private static void getGetActualTypeArguments() throws NoSuchFieldException {
            Field fieldMap = ParameterizedTypeTest.class.getDeclaredField("map");
            ParameterizedType typeMap = (ParameterizedType) fieldMap.getGenericType();
            System.out.println(typeMap.getActualTypeArguments()[0]);
            System.out.println(typeMap.getActualTypeArguments()[1]);
            System.out.println(typeMap.getRawType());
            System.out.println(typeMap.getOwnerType());
        }

        private List<String>[] t;

        private static void testGenericArrayType() throws NoSuchFieldException {
            Field fieldArray = ParameterizedTypeTest.class.getDeclaredField("t");
            GenericArrayType typeArray = (GenericArrayType) fieldArray.getGenericType();
            System.out.println(typeArray.getClass().getName());
            System.out.println(typeArray.getGenericComponentType());
        }

        private List<T> t1;
        private T t2;

        private static void testTypeVariable() throws NoSuchFieldException {
            Field field = ParameterizedTypeTest.class.getDeclaredField("t1");
            ParameterizedType type = (ParameterizedType) field.getGenericType();
            System.out.println(type.getActualTypeArguments()[0].getClass().getName());

            Field field2 = ParameterizedTypeTest.class.getDeclaredField("t2");
            TypeVariable type2 = (TypeVariable) field2.getGenericType();
            System.out.println(type2.getBounds()[0]);
        }

    }

 

ParameterizedType

标签:eva   int   oid   dex   entry   ict   ram   end   map   

原文地址:https://www.cnblogs.com/frankyou/p/13320765.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!