自动化 Python 到 Java 的翻译
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/153491/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Automated Python to Java translation
提问by Victor Noagbodji
Is there a tool out there that can automatically convert Python to Java? Can Jython do this?
有没有可以自动将 Python 转换为 Java 的工具?Jython 能做到吗?
采纳答案by user20149
It may not be an easy problem. Determining how to map classes defined in Python into types in Java will be a big challange because of differences in each of type binding time. (duck typing vs. compile time binding).
这可能不是一个容易的问题。由于每个类型绑定时间的差异,确定如何将 Python 中定义的类映射到 Java 中的类型将是一个很大的挑战。(鸭子输入与编译时绑定)。
回答by Corey Goldberg
to clarify your question:
澄清你的问题:
From Python Source code to Java source code? (I don't think so)
从 Python 源代码到 Java 源代码?(我不这么认为)
.. or from Python source code to Java Bytecode? (Jython does this under the hood)
.. 还是从 Python 源代码到 Java 字节码?(Jython 在幕后做这件事)
回答by oxbow_lakes
Actually, this may or may not be much help but you could write a script which created a Java class for each Python class, including method stubs, placing the Python implementation of the method inside the Javadoc
实际上,这可能有也可能没有多大帮助,但您可以编写一个脚本,为每个 Python 类创建一个 Java 类,包括方法存根,将方法的 Python 实现放在 Javadoc 中
In fact, this is probably pretty easy to knock up in Python.
事实上,这在 Python 中可能很容易实现。
I worked for a company which undertook a port to Java of a huge Smalltalk (similar-ish to Python) system and this is exactly what they did. Filling in the methods was manual but invaluable, because it got you to really think about what was going on. I doubt that a brute-force method would result in nice code.
我在一家公司工作,该公司将一个巨大的 Smalltalk(类似于 Python)系统移植到 Java,这正是他们所做的。填写方法是手动的,但非常宝贵,因为它让你真正思考正在发生的事情。我怀疑蛮力方法会产生好的代码。
Here's another possibility: can you convert your Python to Jython more easily? Jython is just Python for the JVM. It may be possible to use a Java decompiler (e.g. JAD) to then convert the bytecode back into Java code (or you may just wish to run on a JVM). I'm not sure about this however, perhaps someone else would have a better idea.
这是另一种可能性:您能否更轻松地将 Python 转换为 Jython?Jython 只是用于 JVM 的 Python。可以使用 Java 反编译器(例如 JAD)将字节码转换回 Java 代码(或者您可能只想在 JVM 上运行)。但是,我不确定这一点,也许其他人会有更好的主意。
回答by Luke Stanley
Yes Jython does this, but it may or may not be what you want
是的 Jython 这样做,但它可能是也可能不是您想要的