I have the following code that give me trouble compiling.
Give me this error
Error:(20, 22) java: incompatible types: com.company.Main.Impl cannot be converted to T
I only need that interface to work in this function, and I don't want to change the function body much.
Why doesn't this work? and How could I make this work?
package com.company;
public class Main {
class Impl implements someinterface, anotherinterface{
@Override
public Integer getInteger() {
return 0;
}
}
class BigObject{
public Impl get(){
return new Impl();
}
}
private <T extends someinterface & anotherinterface> Integer myfunc(BigObject bg){
T xy = bg.get(); // this line will not compile????
if (xy.isOK()) // from someinterface
return xy.getInteger(); // from anotherinterface
return null;
}
public static void main(String[] args) {
// write your code here
}
}