[Mono-list] Java Convert to C#
Jonathan Pryor
jonpryor at vt.edu
Thu Sep 11 20:44:24 UTC 2014
On Sep 11, 2014, at 9:50 AM, mutasim <d_mutasim at hotmail.com> wrote:
> i convert java code to C# but there is a lot of error the code is connected to C directly the file that been converted : openjdk-7-fcs-src-b147-27 jun 2011
Just offhand...are you aware of the semantic differences between Java and C#, particularly when it comes to generics? Porting Java to C# will be an "interesting" exercise, and I can see from the generated code that it's not going to work:
// from Java/java/lang/Class.cs:
public static Class<?> forName(string name, bool initialize, ClassLoader loader)
`Class<?>` is perfectly fine for Java, but (1) is not valid C#, and (2) has no real equivalent in C# either. The underpinnings of Java type erasure compared to C#'s reified generics are just completely different. "Squaring this circle" will be a "fun" exercise.
Then there's covariant return types (used in java.lang.Appendable & java.lang.AbstractStringBuilder), name resolution and overloading differences...
> why some of the programs in mono back to java , in java is powerful language, and also you can program java with the C# if the java is CLI
I'm not sure what to make of this either.
Running Mono programs on Java will be a difficult exercise for a variety of reasons, including differences in generics, but also in Platform Invoke, GC heap pinning, and more.
Running Java programs atop Mono can already be done without porting the Java code to C#; that's what IKVM is for. IKVM also allows Java code to interact with C# code.
- Jon
More information about the Mono-list
mailing list