在 Jython 中监听 EventBus
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定错误消息是否具有误导性,但您的代码还有其他一些地方看起来很奇怪。我希望
subscribe
的 second 参数是一个EventTopicSubscriber
instance - 你已经传递了一个 类。也许更合适?
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 anEventTopicSubscriber
instance - you've passed a class. Perhapsis more appropriate?