ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From St├ęphane Bailliez <sbaill...@imediation.com>
Subject Re: Question about compiler error when calling log()
Date Sat, 06 Jan 2001 23:00:06 GMT
Hi Diane,

----- Original Message -----
From: "Diane Holt" <holtdl@yahoo.com>

> 137.     log(src + " is not a valid file.", Project.MSG_WARN) ;
>          <->
> *** Error: An instance of "SoundTask.this" is not accessible here because
> it would have to cross a static region in the intervening type
> "SoundTask$BuildAlert".

This is because BuildAlert is a static inner class and thus cannot reference
implicitely SoundTask.log()

When an inner class is not static the compiler add a reference to its outer
class.

class Outer {
    class Inner {
        ..
        log("something"); // this is the same as
Outer.this.log("something");
    }
}

class Outer {
    static class Inner {
        ..
        log("something"); // not possible, Inner doesn't have access to
Outer instance
    }
}

You could either:
1) make your inner class non static (I just look at it briefly but It seems
that the only place where it could have a sense to be created would be the
soundtask itself, so it is probably the best solution so far. The factory
methods are in the soundtask itself.)

2) subclass your static class so that your subclass is non static.
class MySecureBuildAlert extends BuildAlert {
    public File getSource(){
        log("getting source");
        return super.getSource();
    }
}
fail = new MySecureBuildAlert();

I'm not sure what I said is meaningful...so just tell me, if you don't
understand.

Use solution one for now. Unless I didn't sleep enough this should work fine
without side effects.

--
Stephane Bailliez, Paris - France

Mime
View raw message