简体   繁体   English

具有相同名称的Jython覆盖方法

[英]Jython override method with same name

I saw a similar problem occurred on JRuby back in 2010 when we would try to override in Jruby a method that was overloaded orginally on the java source code. 我在2010年看到类似的问题发生在JRuby上,当时我们试图在Jruby中覆盖一个在java源代码上重载的方法。 How do we deal with this in Jython? 我们如何在Jython中处理这个问题? More specifically, how can i specify for one of the methods that are overloaded to be override and ignore the remaining or how can I override all of them? 更具体地说,我如何指定其中一个重载方法被覆盖并忽略剩余的方法或如何覆盖所有方法?

Thank you 谢谢

Python does not support method overloading (but it does support default values). Python不支持方法重载(但它支持默认值)。

def my_function(paramA, paramB = None):
  pass

Since Jython is merely a Python implementation, I belive the same stands true. 由于Jython只是一个Python实现,我相信同样的立场。

To call a specific Java method from Jython, you may have to make the types match very closely, or even exactly. 要从Jython调用特定的Java方法,您可能必须使类型非常接近,甚至完全匹配。

Jython does some type coercion , but there are situations in which this does not select the the method you want. Jython做了一些类型强制 ,但在某些情况下,这不会选择你想要的方法。

To call public methods on specific base classes you can use BaseClass.method(self, ...) . 要在特定基类上调用公共方法,可以使用BaseClass.method(self, ...) To call protected methods you must prefix the method name like self.super__method(...) . 要调用受保护的方法,必须为方法名称self.super__method(...) 前缀 ,例如self.super__method(...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM