Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] DeclareMixin with a java API class as the mixin target.

Hello,
 
I wish to mixin my classes into the Swing classes but I was surprised that my code below didn't work: there was a cast exception. I've mixed in to my own target class okay so I think it's not my setup issue.
 
I'm quite keen for this to work so I was wondering if this is currently a limitation or is it possible? I'm using Maven plugin with 1.6.5 rt and annotations - I didn't try the direct syntax style yet.
 
I wonder if it's caused by order of class loading, but then around advice on Container methods proved to work for me.
 
with best regards,
Nic.
 
 
import java.awt.Container;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclareMixin;
 
@Aspect
public class App
{
    @DeclareMixin("java.awt.Container")
    public Mixin createContainerMixin(){
                return new MixinImpl();
    }
    public interface Mixin {
        void baz();
    }
    public class MixinImpl implements Mixin {
        public void baz(){
                   System.out.println("baz mixed in !");
        }
    }
    public static void main( String[] args )    {
        Container c = new Container();
        Mixin ci = (Mixin) c;
        ci.baz(); // I get class cast exception here.
    }



Use Hotmail to send and receive mail from your different email accounts. Find out how.

Back to the top