Can I use two Java classes with the same name and the same package?

Can I import and use two different classes with the same name and package in Java?

For example, suppose I have two classes called "com. Foo. Bar", which are slightly different I wish I could use both, but I have a limitation (because of stupid reflective garbage) that forces me to keep the name and packaging the same

Are there any Java features that will allow me to import and isolate each of these classes?

To be specific, I changed my Avro mode and they shouldn't be changed (Oops!), Now I want to go back and change the old Avro file. I can't read the file in my new mode. I can read it in my new mode Avro seems to force you to load files with specific class and package names

Solution

Right here. You need to implement your own classloader and play some games to access it at runtime

I'm sure this is possible because I encountered a problem that is difficult to debug. Some of them have a strange classloader in their product, which is to mess up the loading library, and provide two different versions of the same file from two different versions of the library

However, it sounds like an incredibly bad idea I'll go back and find a different way to solve your problem This will only make your heart ache for a long time This may already be the case when you investigate class loaders

Edit: specifically, you cannot import But you can access both at runtime

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>