[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] constructor problem in inner class
|
Hello,
hmmm ... strange if I try to reproduce you problem it looks like the
opposite to me.
The given pointcut matches the inner class "Inner" but not the static
inner class "Inner0".
This is the behavior I would expect.
May be you or I ;-) mixed up something.
have a look at this:
Aspect:
[code]
package de.tutorials.training.aspects;
public aspect ExampleAspect1 {
before() : execution(*..new(*, ..)){}
}
[/code]
Example:
[code]
package de.tutorials.training;
public class InnerClassExample {
public static void main(String[] args) {}
class Inner{ //Advised case1
}
static class Inner0{ //Not Advised case2
}
}
[/code]
Decompiled:
[code]
package de.tutorials.training;
import de.tutorials.training.aspects.ExampleAspect1;
public class InnerClassExample{
public static void main(String[] args){}
class Inner{
private Inner(){
ExampleAspect1.aspectOf().ajc$before$de_tutorials_training_aspects_ExampleAspect1$1$8d2f7ddc();
}
}
static class Inner0{}
}
[/code]
I *think* the given pointcut matches case1 because an instance of the
inner class Inner can only be created in the
context of an instance of the outer class (InnerClassExample) -> new
InnerClassExample().new Inner();
A static inner class is NOT bound to the context of the outer class and
thus doesn't require an Instance of the outer class
and thus doesn't need to be advised.
So in case of an (non static) inner class there must be an instance of
the outer class. I think this implicitly triggers
the match here (some how..)
Please correct me if I'm wrong :)
Best regards,
Thomas
Oliver Böhm schrieb:
Hello,
I want to know if there are known problems with inner classes. I have
an (empty) inner class:
private static class InnerClass {
}
It seems that my pointcut
execution(*..new(*, ..))
matches also the constructor of this inner class. Is this possible?
If I put an (empty) constructor inside it works as expected (the
pointcut does not match)
private static class InnerClass {
public InnerClass() {}
}
And how can I exclude the inner classes from the pointcut?
regards,
Oliver