Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Bad code smells in AspectJ?

Hi,

I have an issue where I am seeing the same kind of code in several of my
aspects.  For example in the following SomeClass appears at several points
which makes me think generics would be a solution.


public aspect X  {
    pointcut myPct() : call(public SomeClass.new());
    
    SomeClass around() : myPct()  {
        if(someTest)  {
            SomeClass s = new SomeClass();  
            // do something with s
            return s;
        }
        else proceed();
    }
}


Generic version.

abstract aspect X<T>  {
    pointcut myPct() : call(public T.new());
    
    T around() : myPct()  {
        if(someTest)  {
            T s = new T();  // error
            // do something with s
            return s;
        }
        else proceed();
    }
}


Unfortunately, it is not possible to instantiate a generic type from within
the aspect.  Just wondering if there was a way around this?   

Regards
Neil 



Back to the top