sarat poluri <sarat.pol...@gmail.com> wrote on 12/08/2009 05:31:02 PM:
> Hi, > > Could you please tell me the syntax to use templates in x10. First off, which version of X10 are you using? The following is for X10 2.0. If by templates you mean generics, then here are some examples: class C[T] { // generic class private val x:T; public def m(v:T):T { ... } public static def g[U](v:U):U { ... } // generic method } The method g() above is static because we don't yet support generic virtual methods. Note that these aren't C++-style templates. In particular, you can't access the type parameter in a static context, nor can you create an instance of the type parameter, nor do you have structural resolution of methods/fields/operators. Also, static methods live in the non-generic incarnation of the class (thus, C.f(), not C[T].f()). One can, however, constrain the type parameter to implement some interface or extend some class, by adding a type constraint like class C[T]{T <: I} { // generic class, T is constrained to extend/implement I ... } Hope this helps, 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/) ------------------------------------------------------------------------------ Return on Information: Google Enterprise Search pays you back Get the facts. http://p.sf.net/sfu/google-dev2dev _______________________________________________ X10-users mailing list X10-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/x10-users