是否有将 C# 代码转换为 Java 代码的有效工具?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/78811/
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
Is there an effective tool to convert C# code to Java code?
提问by
Is there an effective tool to convert C# code to Java code?
是否有将 C# 代码转换为 Java 代码的有效工具?
回答by scubabbl
They don't convert directly, but it allows for interoperability between .NET and J2EE.
它们不直接转换,但允许 .NET 和 J2EE 之间的互操作性。
回答by Roger Ween
There is a tool from Microsoft to convert java to C#. For the opposite direction take a look hereand here. If this doesn't work out, it should not take too long to convert the source manually because C# and java are very similar,
Microsoft 有一个工具可以将 java 转换为 C#。对于相反的方向,请查看此处和此处。如果这不起作用,手动转换源代码应该不会花太长时间,因为 C# 和 java 非常相似,
回答by Michael Meadows
I have never encountered a C#->Java conversion tool. The syntax would be easy enough, but the frameworks are dramatically different. Even if there were a tool, I would strongly advise against it. I have worked on several "migration" projects, and can't say emphatically enough that while conversion seems like a good choice, conversion projects always always alwaysturn in to money pits. It's not a shortcut, what you end up with is code that is not readable, and doesn't take advantage of the target language. speaking from personal experience, assume that a rewrite is the cheaper option.
我从未遇到过 C#->Java 转换工具。语法很简单,但框架却大不相同。即使有工具,我也会强烈建议不要使用它。我曾参与过几个“迁移”项目,并且不能强调地说虽然转换似乎是一个不错的选择,但转换项目总是总是会变成钱坑。这不是捷径,你最终得到的是不可读的代码,并且没有利用目标语言。从个人经验来看,假设重写是更便宜的选择。
回答by Michael Meadows
C# has a few more features than Java. Take delegates for example: Many very simple C# applications use delegates, while the Java folks figures that the observer pattern was sufficient. So, in order for a tool to convert a C# application which uses delegates it would have to translate the structure from using delegates to an implementation of the observer pattern. Another problem is the fact that C# methods are not virtual by default while Java methods are. Additionally, Java doesn't have a way to make methods non virtual. This creates another problem: an application in C# could leverage non virtual method behavior through polymorphism in a way the does not translate directly to Java. If you look around you will probably find that there are lots of tools to convert Java to C# since it is a simpler language (please don't flame me I didn't say worse I said simpler); however, you will find very few if any decent tools that convert C# to Java.
C# 比 Java 有更多的特性。以委托为例:许多非常简单的 C# 应用程序使用委托,而 Java 人员认为观察者模式就足够了。因此,为了使用工具转换使用委托的 C# 应用程序,它必须将结构从使用委托转换为观察者模式的实现。另一个问题是 C# 方法默认不是虚拟的,而 Java 方法是。此外,Java 没有办法使方法非虚拟。这会产生另一个问题:C# 中的应用程序可以通过多态性以不直接转换为 Java 的方式利用非虚拟方法行为。如果您环顾四周,您可能会发现有很多工具可以将 Java 转换为 C#,因为它是一种更简单的语言(请不要 t fire me 我没有说更糟我说的更简单);但是,您会发现很少有像样的工具可以将 C# 转换为 Java。
I would recommend changing your approach to converting from Java to C# as it will create fewer headaches in the long run. Db4Objects recently released their internal tool which they use to convert Db4o into C# to the public. It is called Sharpen. If you register with their site you can view this link with instructions on how to use Sharpen: http://developer.db4o.com/Resources/view.aspx/Reference/Sharpen/How_To_Setup_Sharpen
我建议您更改从 Java 转换为 C# 的方法,因为从长远来看,它会减少麻烦。Db4Objects 最近发布了他们用于将 Db4o 转换为 C# 的内部工具。它被称为锐化。如果您在他们的网站上注册,您可以查看此链接以及有关如何使用 Sharpen 的说明:http: //developer.db4o.com/Resources/view.aspx/Reference/Sharpen/How_To_Setup_Sharpen
(I've been registered with them for a while and they're good about not spamming)
(我已经在他们那里注册了一段时间,他们很擅长不发送垃圾邮件)
回答by karlipoppins
回答by Ian Patrick Hughes
This is off the cuff, but isn't that what Grasshopperwas for?
这是现成的,但这不是Grasshopper 的用途吗?
回答by Ian Patrick Hughes
回答by Mike Rustici
We have an application that we need to maintain in both C# and Java. Since we actively maintain this product, a one-time port wasn't an option. We investigated Net2Java and the Mainsoft tools, but neither met our requirements (Net2Java for lack of robustness and Mainsoft for cost and lack of source code conversion). We created our own tool called CS2Jthat runs as part of our nightly build script and does a very effective port of our C# code to Java. Right now it is precisely good enough to translate our application, but would have a long way to go before being considered a comprehensive tool. We've licensed the technology to a few parties with similar needs and we're toying with the idea of releasing it publicly, but our core business just keeps us too busy these days.
我们有一个需要在 C# 和 Java 中维护的应用程序。由于我们积极维护此产品,因此无法选择一次性端口。我们研究了 Net2Java 和 Mainsoft 工具,但都没有满足我们的要求(Net2Java 缺乏健壮性,Mainsoft 成本高且缺乏源代码转换)。我们创建了自己的名为CS2J的工具,它作为我们每晚构建脚本的一部分运行,并将我们的 C# 代码非常有效地移植到 Java。现在,它足以翻译我们的应用程序,但在被视为一个综合工具之前还有很长的路要走。我们已经将这项技术授权给了一些有类似需求的团体,我们正在考虑公开发布它的想法,但我们的核心业务现在让我们太忙了。
回答by Hannoun Yassir
Well the syntax is almost the same but they rely on different frameworks so the only way to convert is by getting someone who knows both languages and convert the code :) the answer to your question is no there is no "effective" tool to convert c# to java
好吧,语法几乎相同,但它们依赖于不同的框架,因此转换的唯一方法是让懂两种语言的人转换代码:) 你的问题的答案是不,没有“有效”的工具来转换 c#到爪哇