[Mono-list] Mono/Java interop?

fgonthier@hermes.usherb.ca fgonthier@hermes.usherb.ca
Wed, 06 Nov 2002 14:08:59 -0500 (EST)


En réponse à Gopal V <gopalv82@symonds.net>:
 
> How do you plan to go ahead with the bridge ? ... Is it a runtime
> bridge
> or just a compiler/convertor bridge ?...

I think a runtime bridge would be more interresting.  I don't know much about 
compilation Java bytecode, IL thingees that would be required to write a 
compiler/convertor bridge.
 
> > Before I start anything I'd like to know if there is anything similar
> in 
> > development somewhere.
> 

[snip interresting but off-topic projects of Mono to Java converters]

> > I'd also like to have quick opinions on how such a things could be 
> > implemented.  I have few design options myself but I'd like to know
> yours to 
> > see if I'll work the right way.
> 
> A runtime bridge was demonstrated with partial success by a guy (IIRC
> it
> was called IKVM)... But that had a lot of problems and was focussed
> more
> on running JNI in C# .. viz emulate JNI using PInvoke at runtime ...
> The
> target was AWT from ClassPath into C# ...

THAT is what I'd like to hear about:

For example, I'd like to do:

  jObject = JavaNew("Some.Precious.Java.API.Of.Mine.SomeClass");
  jObject.SomeMethodOfSomeClass();

I've read somewhere that C# doesn't do late binding automagically like VB.NET 
does so this little sample probably can't be done that simply.

So we'd probably need some a program that generates C# code from a Java class:

public class JavaSomeClass {
  ...
  public Object SomeMethodOfSomeClass() {
  Object retVal;
    retVal = CallJavaMethod("SomeMethodOfSomeClass");
    return ToIL(retVal);
  ...
  }
}

But couldn't this skeleton be produed "on-the-fly" in C# when the Java object 
is instanciated?

That's the way I see it for now.  I suppose there is alot of work to do using 
JNI and P/Invoke behind the hypothetics CallJavaMethod and ToIL functions.

Most people around here know more about Java and .NET than me and will probably 
laugh at this idea.  But I'd like to hear what would make this idea impossible 
to realize if it's impossible and if there is a better or simpler way to do 
it... 

I only want to discuss this for now.  It's not like I'll sit home tonight and 
start coding ;)  Maybe this thread will give ideas to other too.  Brainstorming 
is always welcomed I think.