Using Java Reflections to retrieve member classes

Posted by darkie15 on Stack Overflow See other posts from Stack Overflow or by darkie15
Published on 2010-04-21T02:27:56Z Indexed on 2010/04/21 2:33 UTC
Read the original article Hit count: 363

Filed under:
|

Hi All,

I am using .getDeclaredClasses() method to retrieve all the classes that have been defined in object. However, I am not able to retrieve anonymous classes defined in the class. Here is the code sample that I am testing:

public class TempCodes
{
  public static void main(String[] args)
  {
    Ball b = new Ball()
    {
      public void hit()
      {
        System.out.println("You hit it!");
      }
    };
    b.hit();
  }

  interface Ball {
    void hit();
  }
}

and this is what my code does:

  memClass = className.getDeclaredClasses();
  if (memClass .length > 0) 
  {
        for (int index = 0 ; index < memClass .length ; index++)
        {
            System.out.println("\t\t\t" + memClass [index]);
        }
  }

Can anyone help me understand how to retrieve the anonymous class?

Regards, darkie

© Stack Overflow or respective owner

Related posts about java

Related posts about reflection