It is technically possible. But only if you put the Java source code (with the same name / package) into separate source trees and compile them separately.
And then, if you want to use the compiled classes (with the same name / package) in one application, the application needs to use multiple classloaders with different classpaths, and other funky things.
And then, you run into all sorts of odd behaviors; e.g. exception messages like "cannot cast foo.Bar to foo.Bar"
Don't go there. It is better to use different classnames and / or different package names.
本文探讨了将Java源代码分别编译成独立class文件的实践挑战,包括使用多ClassLoader、复杂路径管理及可能遇到的运行问题。建议避免使用相同名称和包的类名,以减少潜在的古怪行为和错误消息。

被折叠的 条评论
为什么被折叠?



