zoukankan      html  css  js  c++  java
  • ParameterizedType

       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]);
            }
    
        }
  • 相关阅读:
    MD5加密Java实现
    一直以来有个问题我没有解决,现在知道了
    从最近一次Struts 2 的漏洞看Web安全
    Android与Struts2、Hibernate打造社交平台
    Android与服务器端交互
    大二生活总结
    throttle_classes 60秒访问10次限制
    restframework流程
    django-admin有用的设置
    django-ckeditor设置
  • 原文地址:https://www.cnblogs.com/frankyou/p/13320765.html
Copyright © 2011-2022 走看看