gpt4 book ai didi

java - 如何从嵌入式 Jython 中调用 java 函数?

转载 作者:行者123 更新时间:2023-11-30 05:03:08 26 4
gpt4 key购买 nike

我创建了一个 PythonInterpreter 对象,并且想要调用 java 函数,但不断收到错误:

Exception in thread "main" Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'jytest2' is not defined
Java Result: 1

如何从实时运行的系统调用 java 函数?

public static void main(String args[])
{
ModRet modRet = new ModRet();
jytest();
}

public void jytest()
{
PythonInterpreter interp = new PythonInterpreter();

interp.exec("print \'Hello; jython has successfully been embedded!\'");
interp.exec("print " + FPS);
interp.exec("jytest2()");

}

public void jytest2()
{
System.out.println("HIHIHI");
}

最佳答案

我通常发现我需要使用对象工厂模式并通过接口(interface)调用事物,如 Jython Book - Chapter 10 中所述。

我仍然不太清楚你想要完成什么,所以我没有任何代码给你;但我相信您会发现这本书很有帮助。

关于java - 如何从嵌入式 Jython 中调用 java 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5983823/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com