如何在Jython intepreter中将Jython类转换为Java类?
我正在尝试用ESPERAPI注册一个用户定义的函数。它采用类或字符串类型参数 错误消息如何在Jython intepreter中将Jython类转换为Java类?,java,python,jython,esper,Java,Python,Jython,Esper,我正在尝试用ESPERAPI注册一个用户定义的函数。它采用类或字符串类型参数 错误消息 AttributeError: class MyUdf has no attribute 'getClass' 我可以通过 from java.lang import Math conf.addImport(Math) @larsmans:类似乎只存在于Java类中 class MyUdf(): @staticmethod def udf(): return 50
AttributeError: class MyUdf has no attribute 'getClass'
我可以通过
from java.lang import Math
conf.addImport(Math)
@larsmans:类似乎只存在于Java类中
class MyUdf():
@staticmethod
def udf():
return 50
def main():
a = 'abc'
print a.__class__
u = MyUdf
print u.__class__
Traceback (most recent call last):
line 79, in main print u.__class__ AttributeError: class MyUdf has no attribute '__class__'
我认为这是不可能的。Jython类不是Java类,据我所知,没有纯Jython机制来实现它 一般来说,我认为应该采用对象工厂方法,并与代理类相结合,这是作为参数传递的 然而,这种方法需要编写大量的Java,在您的例子中,似乎只需用Java编写MyUdf类并使用它就更简单了
或者,您可以通过动态字节码生成来做一些事情,但这是一个全新的兔子洞…我认为这是不可能的。Jython类不是Java类,据我所知,没有纯Jython机制来实现它 一般来说,我认为应该采用对象工厂方法,并与代理类相结合,这是作为参数传递的 然而,这种方法需要编写大量的Java,在您的例子中,似乎只需用Java编写MyUdf类并使用它就更简单了 或者,您可以通过动态字节码生成来做一些事情,但这是一个全新的兔子洞…conf.addImportMyUdf有效吗?conf.addImportMyUdf有效吗?
class MyUdf():
@staticmethod
def udf():
return 50
def main():
a = 'abc'
print a.__class__
u = MyUdf
print u.__class__
Traceback (most recent call last):
line 79, in main print u.__class__ AttributeError: class MyUdf has no attribute '__class__'