Skip to main content

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

Hi Andy,
Thanks for taking the time for reviewing my code!

A couple of differences :
- I inferred also the Converter field
- TextComponent is a binary class i'm weaving without sources

I'm not in office now, but will try it again later and see if i figure
out by my self where is the difference.

Simone

Andy Clement wrote:
> >From your description it sounds like a bug, but I can't seem to
> recreate it - this file compiles fine for me:
>
> ---
> class TextComponent {
>   Converter converter;
> }
>
> interface Converter<T> {
>   public T fromString(String value);
>   public String toString(T value);
> }
>
> class IntegerConverter implements Converter<Integer> {
>   public Integer fromString(String value) { return null; }
>   public String toString(Integer value) { return null; }
> }
>
> aspect X {
>   Object Converter.component;
>
>   public void TextComponent.setConverter(Converter c) {
>      this.converter = c;
>      c.component = this;
>   }
> }
>
>
>
> public class Test {
>   public static void main(String []argv) {
>    TextComponent tc = new TextComponent() ;
>    IntegerConverter ic = new IntegerConverter();
>    tc.setConverter(ic);
>   }
> }
> ---
>
> Can you tell me what I have done differently to you?  Is your
> TextComponent class generic by any chance?  Is it a binary weave into
> a library or everything being compiled from source?
>
> Andy.
>
> On 11/04/2008, Simone Gianni <simoneg@xxxxxxxxxx> wrote:
>   
>> 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
>>  _______________________________________________
>>  aspectj-users mailing list
>>  aspectj-users@xxxxxxxxxxx
>>  https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>
>>     
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>   



Back to the top