private static <Person> void show(Collection<Person> al) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {//此处为什么不能用Person,必须用通用符吗,为什么也不能用Object,不是说父类指向子类吗,为什么写父类类型不行? 
                Iterator<Person> it = al.iterator(); 
                while(it.hasNext()) { 
                        Person p = it.next(); 
               Method method = p.getClass().getMethod("getName");//我把你第一个show方法这里改成反射就可以了。我不知道为什么不用反射p不能调用getName()方法。而泛型定义Object或者T时,p可以调用getName()方法。 
               System.out.println(method.invoke(p)); 
                         
                } 
        } |