0

I have problem with generics. I'm trying to assign some value to an interface with wildcard <?> and get an error. What would be your advice for refactoring?

The method get( capture#4-of ?) in the type MyInterface is not applicable for the arguments (Object)

class X {
  MyInterface<?> mi;

 <Z> void  init (MyInterface<Z> mi)
    this.mi = mi;
 }

 void doSmth (){ 
   mi.get((Object)1); // hier error
 }
}

interface MyInterface <T> {
   Object get(T something);
}
Tony
  • 2,266
  • 4
  • 33
  • 54
  • The way you are using generics is not in such a way the compiler can infer anything. Even though `Object` is the root of the entire class hierarchy you told the compiler you don't know what the type was. – M. le Rutte Oct 04 '17 at 14:33
  • So should I change `>` to `Object`? – Tony Oct 04 '17 at 14:51

0 Answers0