如果你是想取得inner class的普通方法和构造函数之类的信息,对这个class使用reflection即可,如果你想取得一个class的所有inner class的名称之类的信息,这个好像做不到。

解决方案 »

  1.   

    你的想法和内隐类的存在的部分原因有点冲突,本来inner class 的很大一部分功能就是隐藏机制,不允许别人调用,而refection api在这里你用来发现你所要的类,你说呢,refection api通过设置可以找出private 类,我也没有试过,你看通过设置成private 行不行, 如果不行就不行了,如果你觉得你的inner 类需要被refection api发现的话,那就不要把他写成inner class 因为,refection api里设置只用来发现客户可用的类,还有,你像匿名内隐类没有名字也不允许有构造函数你怎么发现呢,我觉得没有必要,如果你觉得这是个冲突的话,那么你应该考虑一下自己的思路
      

  2.   

    不知道getDeclaredClasses()可不可以做到getDeclaredClasses() Returns an array of Class objects reflecting all the classes and interfaces declared as members of the class represented by this Class object. The getDeclaredClasses() method can be used to find the public, private, or protected member classes declared within the reflected class or interface. Inherited member classes are not returned by this method. If the Class object represents a primitive type, or the class declares no classes or interfaces as members, this method returns an array of length zero. The following code is an example of the usage of the getDeclaredClasses() method: Class instance = Class.forName( "java.net.URLConnection" ); 
    Class[] result = instance.getDeclaredClasses(); 
    我们老师留的一个作业要求用Java Reflection API收集class信息,其中包括inner class....