import - In java how do you refer to a class that is in the default package of a third party library? -


I have downloaded a third party library and have classes I want to refer to in the default package? How can I import these classes?

It is not possible directly with the compiler, the sun removed this ability. If there is a default namespace, then everything should be in the default namespace.

However, you can do this by using the ClassLoader . Assuming the class is called thirdparty , and there is a fixed method call in it doSomething () , you can implement it like this:

  class claz = classloader.get system class loader (). Load class ("Third Party"); Java.lang.reflect. Method method = clazz.getMethod ("doSomething"); Method.invoke (zero);  

It's tedious to say the least ...

Some time ago, before Java 1.5, you were able to import ; Third party; (Anonymous / a square from the default namespace), but no longer look at it. In order to not be able to use classes from the default namespace, it is suggested to use the JDK 1.3.1 compiler to demand an alternative solution.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -