2

We need to pass an x10 arraylist[string] to a Java method as an object. What we tried is this.The method signature in Java interface is as follows.

public void getX10ArrayList ( ArrayList <String > nameList):

We implement that method inside an X10 class as follows.

public def getX10ArrayList ( var names : ArrayList [String] ) {
    // do something
}

We get a compile error saying interface expected an object of type x10.util.ArrayList but we are sending an object of type x10.util.ArrayList[ x10.lang.String]`.

Bohemian
  • 412,405
  • 93
  • 575
  • 722
Nandula
  • 23
  • 4

2 Answers2

0

Don't you need to declare your interface signature as -

Public void getX10ArrayList(ArrayList[String] nameList):
Darpan
  • 5,623
  • 3
  • 48
  • 80
0

Unfortunately, the current X10 type system doesn't allow an X10 class to implement a parameterized Java interface. Although it looks like the right solution is to define the interface as @Darpan suggests:

public void getX10ArrayList(ArrayList[String] nameList);

when the Java interface is type-checked, the type parameter is erased from the X10 interface and so the types are different. Details of the translation from X10 to Java classes can be found in the paper Compiling X10 to Java (Takeuchi et al. 2011).

One possible workaround is to wrap the generic class in a non-parametrized type. For example:

// MyArrayList.java
import java.util.ArrayList;
class MyArrayList {
    public ArrayList<String> list;
}

// X10ArrayListProvider.java
public interface X10ArrayListProvider {
    public void getX10ArrayList(MyArrayList nameList);
}

// ArrayListProvider.x10
import MyArrayList;
import X10ArrayListProvider;
public class ArrayListProvider implements X10ArrayListProvider {
    public def getX10ArrayList(names:MyArrayList):void {
        // ...
    }
}
Josh Milthorpe
  • 956
  • 1
  • 14
  • 27