[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[aspectj-users] Intertype a new constructor and interface
|
Hello,
I want to add a new contructor to all classes that implements a interface,
therefore I use the code bellow:
package untitled4;
public interface Interface1{}
package untitled4;
class Untitled1
{
public void doSomething()
{
System.out.println("No it's an Answer");
}
public static void main(String args[])
{
Untitled1 a = new Untitled1();
a.doSomething();
}
}
package untitled4;
aspect aAspect {
declare parents : Untitled1 implements Interface1;
public Interface1.new(String aString)
{
System.out.prinln(aString);
}
pointcut doSomething() : call(* Interface1+. doSomething(..));
before() : doSomething()
{
new Untitled1("Example");
}
}
I added some code (doSomething) to test if the new constructor is available,
but the compiler gives a warning. Why is the constructor not available on
the classes that implements Interface1? Because if I add new methods on this
way no warning is given and the methods are available. See code below:
package untitled4;
aspect aAspect {
declare parents : Untitled1 implements Interface1;
public void Interface1.aNewMethode(String aString)
{
System.out.println(aString);
}
pointcut doSomething() : call(* Interface1+.doSomething(..));
before() : doSomething()
{
new Untitled1().aNewMethode("ThisWorksFine");
}
}
Greetings,
Bas