本文由我司收集整编,推荐下载,如有疑问,请与我司联系
来自加载类的Java Call类函数
2011/02/25 1277 How would I, if possible, call a function in my Main class in the class that I load? (I know that is impossible to understand, so I’ll explain)
如果可能的话,我如何在我加载的类中调用Main类中的函数? (我知道这是不可能理解的,因此我会解释)
I.E:
public class SomeClass public SomeClass //load a class here public void FuncToCall() {}//In a separate file, dynamically loaded.public class LoadedClass public LoadedClass //Call a function in the class that loads this SomeClass.FuncToCall(); So I would end up having 2 files: SomeClass.class and LoadedClass.class. I guess my main question is, how do I reference SomeClass in LoadedClass?
因此我最终会得到2个文件:SomeClass.class和LoadedClass.class。
我想我的主要问题是,如何在LoadedClass中引用SomeClass?
**EDIT:
So maybe I should better explain the use case. A java program dynamically loads the “SomeClass” script from a folder. The script then downloads a .jar file from the internet and opens and runs the “LoadedClass” script within that. How do I use functions in SomeClass in LoadedClass if SomeClass isn’t in the same .jar or in a .jar at all?
因此也许我应该更好地解释用例。
java程序从文件夹动态加载“SomeClass”脚本。
然后,该脚本从Internet下载.jar文件,并在其中打开并运行“LoadedClass”脚本。
如果SomeClass不在同一个.jar或.jar中,我如何在LoadedClass中的SomeClass中使用函数?
你这样做..
If they are in different packages you have to either import the class or use the fully qualified name.
如果它们位于不同的包中,则必须导入该类或使用完全限定的名称。