Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 2010 年看到 JRuby 上发生了类似的问题,当时我们试图在 Jruby 中覆盖一个在 Java 源代码上最初重载的方法。我们如何在 Jython 中处理这个问题?更具体地说,我如何指定要重载的方法之一被覆盖并忽略其余的方法,或者如何覆盖所有这些方法?
谢谢
Python 不支持方法重载(但它支持默认值)。
def my_function(paramA, paramB = None): pass
由于 Jython 只是一个 Python 实现,我相信这同样适用。
要从 Jython 调用特定的 Java 方法,您可能必须使类型非常匹配,甚至完全匹配。
Jython 会执行某种类型的强制转换,但在某些情况下这不会选择您想要的方法。
要在特定基类上调用公共方法,您可以使用BaseClass.method(self, ...). 要调用受保护的方法,您必须在方法名称前面self.super__method(...)加上.
BaseClass.method(self, ...)
self.super__method(...)