Thanks. Can you please suggest a work around? I need to make function
static, since otherwise it can't be called from main; but I also need to
keep the variable non-static, so that it can be accessed & modified. How to
do that?

Thanks and Regards
Sparsh Mittal



On Wed, Feb 13, 2013 at 4:41 PM, Josh Milthorpe
<josh.miltho...@anu.edu.au>wrote:

>  Also - just as in Java, an instance field can't be accessed from a
> static method (funcWorker).
>
>
> On 14/02/13 09:07, David P Grove wrote:
>
> Hi,
>
>  "val" roughly corresponds to "final" in Java (or const in C++)   To
> declare an instance field you want to be able to modify you need to use
> "var"
>
> var currentWorkCounter: Int =-1 ;
>
> --dave
>
>
> Sparsh Mittal <sparsh0mit...@gmail.com> <sparsh0mit...@gmail.com> wrote
> on 02/13/2013 12:11:46 PM:
> >
> > Hello
> > Here is the minimum working example of what I am trying to do. I
> > want to make currentWorkCounter a non-static member, which multiple
> > functions in the class can use and modify. However, compiler does
> > not allow. Can you please tell how to accomplish.
> >
> > //Does not compile due to non-static member.
> > import x10.io.Console;
> > import x10.lang.Int;
> >
> > public class Test {
> >
> > val currentWorkCounter: Int =-1 ;
> >
> > public  static def funcWorker (myNumber: Int) {
> >   val answer:Int;
> >
> >   atomic {
> >     currentWorkCounter =  currentWorkCounter +1;
> >     answer =currentWorkCounter;
> >   }
> >
> >   Console.OUT.println(myNumber+" did "+ answer);
> >
> > }
> >
> >   public static def main(args: Array[String](1)) {
> >
> >
> >       finish for(var k: Int =0; k< 5; k++) {
> >         val kk = k;
> >
> >         async funcWorker(kk );
> >          }
> >
> >          Console.OUT.println("I am done  " );
> >
> >
> >   }
> > }
> >
>
> > Thanks and Regards
> > Sparsh Mittal
> >
> ------------------------------------------------------------------------------
> > Free Next-Gen Firewall Hardware Offer
> > Buy your Sophos next-gen firewall before the end March 2013
> > and get the hardware for free! Learn more.
> > http://p.sf.net/sfu/sophos-d2d-feb
> > _______________________________________________
> > X10-users mailing list
> > X10-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/x10-users
>
>
> ------------------------------------------------------------------------------
> Free Next-Gen Firewall Hardware Offer
> Buy your Sophos next-gen firewall before the end March 2013
> and get the hardware for free! Learn more.http://p.sf.net/sfu/sophos-d2d-feb
>
>
>
> _______________________________________________
> X10-users mailing 
> listX10-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/x10-users
>
>
>
>
> ------------------------------------------------------------------------------
> Free Next-Gen Firewall Hardware Offer
> Buy your Sophos next-gen firewall before the end March 2013
> and get the hardware for free! Learn more.
> http://p.sf.net/sfu/sophos-d2d-feb
> _______________________________________________
> X10-users mailing list
> X10-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/x10-users
>
>
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013 
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to