简体   繁体   中英

How to compile java class with inner classes?

I need to compile a java class that has multiple inner classes (or nested). Example: Myclass.java Myclass$sub1.class Myclass$sub2.class Myclass$sub2$subsub.class

I need to compile (command line, oracle javac) the file Myclass.java, using the compiled inner class files.

How can this be done? I tried the -sourcepath option, with no luck.

Thanks

You compile a source file , not a source class . Any classes, including nested ones, in that source file are compiled. No special effort required.

javac MyClass.java 

只需编译源文件,它也会自动编译内部类。

The direct and striaght way would be to use javac Myclass.java

Please make sure to check the modifiers being used incase you are experiencing errors while referencing the inner classes. This could be helpful : https://stackoverflow.com/a/70358/2908301

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM