Judah Diament/Watson/IBM@IBMUS wrote on 08/19/2013 04:16:56 PM:
>
> Is there a way to create a Rail whose type is java.lang.Comparable
> (which is an interface), as in
>
> import java.lang.Comparable;
> ...
> val myRail: Rail[Comparable];
>
> where I don't know what the actual class of the instances passed in
> from Java code for myRail to hold will be, but I also don't care
> because all I want is to be able to use the compareTo() method?
>
>
Hi Judah,
In both Java and X10 Comparable is actually Comparable[T] (ie, a
generic interface with one type parameter). Since Java erases generics it
lets you ignore that sometimes. X10 doesn't erase generics, so it is going
to insist that you say Comparable[SOME_TYPE] not just Comparable.
Do you really know nothing about the type parameter of the
Comparable, or will something like the stubbed out code below work for your
usage?
--dave
abstract class A implements Comparable[A] {
public abstract def compareTo(A):int;
}
interface I extends Comparable[I] {
public def compareTo(I):int;
}
public class Test {
public static def main(args:Rail[String]) {
val r = new Rail[Comparable[A]](10);
val r2 = new Rail[Comparable[I]](10);
}
static def test(x:Rail[Comparable[A]], y:A) {
return x(1).compareTo(y);
}
static def test2(x:Rail[Comparable[I]], y:I) {
return x(1).compareTo(y);
}
}
------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and
AppDynamics. Performance Central is your source for news, insights,
analysis and resources for efficient Application Performance Management.
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users