Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] generic return method in aspcet J

Ok ... good news and bad news...

If you want to add a member to a generic type and utilise the type
variables for that type in your own ITD, then you need to specify it
like this:

  Link<T> AssociationSource<T>._target = null;

  public Link<T> AssociationSource<T>.getTarget() {
      return _target;
  }

i.e. you must include the type variable you want to 'reuse' in the
target type you specify.  This would also work:

  Link<X> AssociationSource<X>._target=null;

Since AspectJ will realise that X in your ITD is referring to the
first type variable in the generic type AssociationSource.

Basically we dont just match by the name of the letters matching.  If
you leave it like this:

Link<T> AssociationSource._target = null;

I'd expect a warning saying 'Type T cannot be found' - however, this
doesnt happen and I think thats an AJ bug.

So, I changed the aspect to this:

aspect ExtendProduct {

       Link<T> AssociationSource<T>._target = null;

       public Link<T> AssociationSource<T>.getTarget() {
           return _target;
       }

       public void AssociationSource<T>.setTarget(Link<T> _target) {
           this._target = _target;
       }

       declare parents: ProductType implements AssociationSource<Product>;
       declare parents : Product     implements AssociationSource<Branch>;
       declare parents : Branch      implements AssociationSource<Revision>;
}

and still get the failures you describe.  The next thing I did was
remove the method declarations from the interface, reducing it to:

interface AssociationSource<T> {
}

This then compiles cleanly (I've not got a test program to drive it
though...).  So, it looks like a second AJ bug in that you can't
provide a default implementation for a generic method defined in a
generic interface.  The error message you get when you try is wrong.

Andy.
---
Andy Clement
AspectJ Development


Back to the top