在 Jython 中监听 EventBus

发布于 2024-08-02 08:23:22 字数 591 浏览 4 评论 0原文

我正在尝试使用 Jython 的 EventBus 。从 Jython 总线向 Jython 总线发送事件按预期工作,可以从我的 Java 代码中监听它们。但从 Jython 订阅总线是有问题的。我正在尝试这样做:

class Listener(EventTopicSubscriber):
    def onEvent(self, topic, object):
        print("got an event")

EventBus.subscribe("Topic", Listener)

它给出了以下内容:

TypeError: subscribe(): 1st arg can't be coerced to java.util.regex.Pattern,
java.lang.reflect.Type, String, java.lang.Class

我很惊讶 1st 参数可能有问题。我的理解是它是一个字符串文字,正如它应该的那样。有什么想法吗?

I'm trying to use EventBus from Jython. Sending events to the from Jython bus works as expected, they can be listened from my Java code. But subscribing to the bus from Jython is problematic. I'm trying this:

class Listener(EventTopicSubscriber):
    def onEvent(self, topic, object):
        print("got an event")

EventBus.subscribe("Topic", Listener)

It gives the following :

TypeError: subscribe(): 1st arg can't be coerced to java.util.regex.Pattern,
java.lang.reflect.Type, String, java.lang.Class

I'm surprised that there can be something wrong with the 1st argument. My understanding is that it's a String literal, just as it's supposed to be. Any ideas?

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

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

发布评论

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

评论(1

人│生佛魔见 2024-08-09 08:23:22

我不确定错误消息是否具有误导性,但您的代码还有其他一些地方看起来很奇怪。我希望 subscribesecond 参数是一个 EventTopicSubscriber instance - 你已经传递了一个 类。也许

EventBus.subscribe("Topic", Listener())

更合适?

I'm not sure whether the error message is misleading, but something else looks odd about your code. I would expect subscribe's second argument to be an EventTopicSubscriber instance - you've passed a class. Perhaps

EventBus.subscribe("Topic", Listener())

is more appropriate?

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