#191 How to interact with Java or .NET libraries?

careck Wed 16 Apr 2008

Hi,

I've just jumped here from the reddit post and am thoroughly impressed with what you guys have done here.

One question that I couldn't find answered in the docu is how to talk to Java libraries from a fan program. Especially I would love to use the Swing API in some way.

Cheers, Carsten.

andy Wed 16 Apr 2008

Hey Carsten,

The short answer is you can't directly from Fan. Though better support that type of stuff is on our Roadmap.

Currently the only way to interact with native Java/.NET libraries is to use the native keyword. I'd point you at the Native docs but unfortunately we don't have that information written up yet.

You can look through the inet source code to see how it works - basically when you define a slot as native - you have to create a corresponding Peer class in Java/C#:

// fan impl
class Foo   
{
  native Int bar()
}

// java impl
public class FooPeer
{
  public Int bar(Foo peer) { ... }
}

Login or Signup to reply.