help , inner class included.

hello all : I want to check a java file , which include inner class or not , and I want to get the inner class name of it , how can I do it ?looks like this :java InnerClassChecker Mother.javaInnerClassAInnerClassBInnerClassCthank u.
[289 byte] By [ppgoodboya] at [2007-10-3 8:17:47]
# 1
Add on, Sorry , not only inner class,but also 2 classes which wrotten in one java file. Can I check it out ? help me. thank u !
ppgoodboya at 2007-7-15 3:23:05 > top of Java-index,Java Essentials,New To Java...
# 2

I would suggest compiling Mother.java and then you can do this with the Class object of the mother class.

Class c = motherObj.getClass();

Then you can call c.getClasses(). This will return all public inner Classes of Mother.

If you dont have the mother Object and want to do it with the parameter it would look like this:

java InnerClassChecker Mother.class

Then your InnerClassChecker takes the <param> in its main method and calls

Class.forName(<param>) to load the Mother class object.

erik44a at 2007-7-15 3:23:05 > top of Java-index,Java Essentials,New To Java...
# 3
Hey, 2 class definitions in one java file are not possible!!There can be only 1 class and inner classes within this one class definition.
erik44a at 2007-7-15 3:23:05 > top of Java-index,Java Essentials,New To Java...
# 4
A different approach could be to read the .java file with a FileReader a look for the keyword "class" within the outer class definition. But I dont like thisone.
erik44a at 2007-7-15 3:23:05 > top of Java-index,Java Essentials,New To Java...
# 5

No, it is possible which define 2 class in 1 file .

just like

public class A {

}

class B {

}

when class B is not a public , it is possible .

ppgoodboya at 2007-7-15 3:23:05 > top of Java-index,Java Essentials,New To Java...
# 6

And your way is not possible , when I got Mother.java like this

Mother.java

[code]

public class A {

}

class B {

}

[code]

When I compile it , it becomes A.class and B.class , whick class object should I get ? If A.class include a inner class, may be I can check it out ,

but in this case , 2 class in 1 file, It doesn't work . Can you tell me an other way to do it ?

ppgoodboya at 2007-7-15 3:23:05 > top of Java-index,Java Essentials,New To Java...