Thanks Igor

-----Original Message-----
From: Igor Peshansky [mailto:[email protected]] 
Sent: Monday, 15 June 2009 1:19 PM
To: Miron, David (CMAR, Armidale - Chis)
Cc: [email protected]; [email protected]
Subject: Re: [X10-issues] Calling java from x10

<[email protected]> wrote on 06/14/2009 09:46:25 PM:

> Hi all
> 
> I have been following the development of x10 for the last 12 months 
> and excited about the recent release of the x10DT.
> 
> My question is how do I call a java class from x10?  I have looked 
> everywhere I can think but cannot find a way of doing this.
> 
> That is if I have a class Foo.java with a method littleFoo as follows:
> 
> public class Foo{
>   public int littleFoo(){
>     return 1;
>   }
> }
> 
> How do I call this from an x10 program?
> 
> Thanks and any help appreciated.
> David

Hi, David,

Thank you for your interest in X10.

First, x10-issues is not the right list for X10-related questions --
it is for automatic reports on JIRA updates.  Redirecting to the
x10-users list.  Please remove x10-issues from your reply.

Second, there is currently no robust mechanism for invoking target
language code from X10.  There is a (rather fragile) @Native
mechanism, used by our library implementation.  Please be aware
that using the @Native mechanism requires some amount of knowledge
about the working of the X10 system (including the compiler).

Here's how you would use @Native for your example:

====== InvokeFoo.x10 ======
public class InvokeFoo {
  public static def main(Rail[String]) {
    Console.OUT.println("Foo.littleFoo() returned "+invokeLittleFoo());
  }
  @Native("java", "new Foo().littleFoo()")
  public native def invokeLittleFoo(): Int;
}
===========================

Note that I did not pass an object of (Java) type Foo around.  It
is possible to some extent, but you would need more elaborate
mechanisms.  It's usually better to restrict yourelf to invoking
static methods on Java classes.

The above also will not work for the C++ backend, and you would
have to fully qualify Foo, because there is no control over imports.

For more examples, see the X10 runtime sources (written in X10).
Hope this answers your question.  If you have more questions, please
post to x10-users -- we will gladly answer them.
        Igor
-- 
Igor Peshansky  (note the spelling change!)
IBM T.J. Watson Research Center
XJ: No More Pain for XML's Gain (http://www.research.ibm.com/xj/)
X10: Parallel Productivity and Performance (http://x10.sf.net/)


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
X10-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to