|
Shouldn't it work?
Comrades, there is no way to directly call a packageless class with a packaged class, because the packageless class is placed in a hidden namespace.
Use reflection to call it.
Suppose there is a non-package class that needs to be called:
[code=Java]public class Main {
public void hello() {
System.out.println("hello");
}
}[/code]
Use reflection to call the hello() method of this packageless class:
[code=Java]package hello;
import java.lang.reflect.*;
public class Hello {
public static void main(String[] args) throws Exception {
Class clazz = Class.forName("Main");
Object o = clazz.newInstance();
Method m = clazz.getDeclaredMethod("hello");
m.invoke(o);
}
}[/code] |
|