in our case the desire is to know absolutely nothing about the type
parameter.
Thanks,
Judah Diament
IBM T.J. Watson Research Center
P.O. Box 704 Yorktown Heights, NY 10598, USA
914-784-7813 (TL: 863)
"Successful innovators use both the right and left sides of their brains.
They look at figures. They look at people. They work out analytically what
the innovation has to be to satisfy an opportunity. Then they go out and
look at potential users to study their expectations, their values, and
their needs."
-Peter F. Drucker
From: David P Grove/Watson/IBM@IBMUS
To: Mailing list for users of the X10 programming language
<x10-users@lists.sourceforge.net>,
Date: 08/19/2013 06:18 PM
Subject: Re: [X10-users] a Rail of comparables
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
------------------------------------------------------------------------------
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