Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Method override "conflicts with existing member"

Is it possible to override methods in classes that do not belong to the current
project?  Consider:
public class A {
   public void a() { }
}

A comes from a different project.  We want to override a() in the current
project (anything that implements a given interface should use our alternative
implementation):
public interface AOverride {
   static aspect IMPL {
      public void AOverride.a() { }
   }
}

public class B extends A implements AOverride { }

The above, specifically the aspect, will not compile with the following error:
inter-type declaration from eheh.AOverride$IMPL conflicts with existing member:
void eh.A.a()

I'll note that you'll get no such compile-time errors if you override any of the
methods of java.lang.Object (which clearly is not being compiled by the current
project).  You can, for example, introduce the toString method in the above
aspect without error.  However, if you, similarly, override toString in A,
you'll get a compile-time error.  I'll also note that if you move A into the
current project, the above will compile.

Is there a way to make this work?  Is there a particular reason some overrides
are allowed but others are not?  (Note:  the around/before/after advice will
not match using compile-time weaving because the current setup won't weave A. 
I realize I could use either load-time weaving or weave A as a post-compilation
step, but I'd prefer not to do either (if possible).)


Back to the top