0

I have this API which I can't change:

public interface A<T> {
  void onClick(T widget);
}
public interface B<T> {
  void use(A<T> a);
}

public interface C {
  B<?> apply();
}

I have an instance c of a C object, and I need to call apply(), and then call use() on the result and provide an Anonymous Inner Type. Here is what I tried:

B<Object> b = (B<Object>) c.apply();
b.use(new A<Object>() {
   onClick(Object o) {
   }
 });

This works, however it produces a unchecked warning. Is it possible to avoid it?

Thanks

  • The answer has been marked as a duplicate, but I don't see how the duplicate answer (which I had already looked at before creating my own) answers my question (it just talks about generics in general, but doesn't ask my precise question)... Does it mean I can't avoid the warning ? There is apparently a whole tag on unchecked warnings and another one on generics, it's sad that I can't ask my own question, I still don't know what to do with my code :(. – Karlzio Jan 16 '17 at 04:05
  • *Ideally*, rejigger your generics so that you have consistent return types. You could have a `C`, for example. – chrylis -cautiouslyoptimistic- Jan 16 '17 at 04:24
  • @chrylis Thanks for your response. However as mentioned in my question, C is not an generic object, and it's part of the API, I can't change it – Karlzio Jan 16 '17 at 04:28

0 Answers0