Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] Inferred method having a generic as argument

Hello all,
I'm moving my first steps in this beautiful world of AOPized Java, but
in the last 3 hours I've been facing a problem I don't know how to
solve. Probably it is just a stupid thing, but still ....

I have a class, called TextComponent, on which I'm trying to add via
AspectJ a field and a couple of methods. One of the methods is declared
this way in my aspect :

    public void TextComponent.setConverter(Converter c) {
        this.converter = c;
        c.component = this;
    }

Now, Converter is a generic interface :

public interface Converter<T> {

    public T fromString(String value);
   
    public String toString(T value);

}


Which then has an implementation :

public class IntegerConverter implements Converter<Integer> {
....
}


Now, I weave the project containing TextComponent, i get the method
added, but then when i try to do :

TextComponent tc = new TextComponent();
IntegerConverter ic = new IntegerConverter();
tc.setConverter(ic);

I get an error, both from AJDT inside Eclipse and from ajc invoked in
the Maven build. The error is :

The method setConverter(Converter<T>) in the type TextComponent is not
applicable for the arguments (IntegerConverter)

Mh, I tried this on a plain class, instead than on an inferred method,
just to make sure I was not missing something in the generics field. I
also tried to declare the method differently (like
setConverter(Converter<?> c) etc..) .. but still it does not work.

Declaring it as setConverter(Object c) and then casting c to a Converter
(or Converter<?>) works perfectly.

I'm using version 1.5.4 or AspectJ.


Any idea?

Simone


Back to the top