Jython:访问单例 Java 类(静态)

发布于 2024-09-15 09:25:00 字数 310 浏览 3 评论 0原文

我似乎无法获得完全正确的语法:我有一个 Jython 脚本和一个 Java 应用程序加载到同一个 JVM 中(用于测试)。

我需要通过 Jython 脚本中的 Singleton 类访问应用程序的特定部分。我该怎么做?

谢谢


编辑:

该设置用于自动化测试,因此假设 Jython 脚本已经可以访问 Java 应用程序的类/类路径。

假设我的 Java 应用程序有一个单例类 some.pkg.MySingleton
.. 如何从 Jython 脚本调用 MySingleton.getInstance()?

I cannot seem to get the syntax quite right for this: I have a Jython script and a Java application loaded into the same JVM (for testing).

I need to access a particular part of the application through a Singleton class from the Jython script. How do I do this?

Thanks


EDIT:

The set up is for automated testing, so assume that the Jython script already has access to the classes/classpath of the Java application.

Let's say my Java application has a singleton class some.pkg.MySingleton
.. how do I invoke MySingleton.getInstance() from my Jython script?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

影子的影子 2024-09-22 09:25:01

这没起作用吗?

from some.pkg import MySingleton

myInstance = MySingleton.getInstance()

如果这不起作用,请尝试以下操作:(我不确定这是否有效)

mySingletonClass = MySingleton(MySingleton)
myInstance = mySingletonClass.getInstance()

Didn't this work?

from some.pkg import MySingleton

myInstance = MySingleton.getInstance()

If that doesn't work, try this: (I'm not sure if this works)

mySingletonClass = MySingleton(MySingleton)
myInstance = mySingletonClass.getInstance()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文