Tuesday 15 September 2015

java - anonymous class extending an abstract class -



java - anonymous class extending an abstract class -

i'm looking schedule task @ specified time starttime, , when time comes, want run method rrun(boolean param1, object someobj).

rrun() method in class, someclass.

and, within someclass again, have method m1() part of code:

timer starttimer = new timer(); starttimer.schedule(new timertask() { public void run() {rrun(false, this);} }, starttime);

to this, i'm getting error

incompatible types: <anonymous timertask> cannot converted someclass

what's wrong i'm doing?

tia.

//===============================

edit:

i'm using jdk 8 -- latest one

inside anonymous inner class, this reference current timertask anonymous subclass, not enclosing class.

to refer enclosing class, qualify this:

public void run() {rrun(false, someclass.this);}

java anonymous-types

No comments:

Post a Comment