[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Using AspectJ to error when an implementing class does not declare a constructor
|
Hi,
I don't think this question has come up before but is it possible, with
AspectJ, to declare an aspect that catches any classes that implement an
interface but do not declare a particular constructor?
For instance, I have a Module interface something like this:
public interface Module {
public interface ModuleContext {
String getSetting(String name);
}
}
Now, every class that implements the Module interface must (because of
the way they are created through reflection) declare a constructor that
takes a ModuleContext instance:
public class FooModule implements Module {
public FooModule(ModuleContext context) {
// get some settings from context
}
}
But in Java you cannot enforce this at compile time, with interfaces (I
know I could do an abstract class but this will open up another whole
can of worms for me). For instance, the interface below is invalid as
it doesn't have this constructor but the developer is not informed of
this at compile time:
public class BadModule implements Module {
}
So, I was wondering if there is some way, using 'declare error' that I
can spot this error at compile time?
Go slow, slightly new to AspectJ!
Matt