I am relatively scaled at beginner level of knowledge in Advanced Java Generics. I wanted to define a interface something like this
public interface Transformer {
<T extends String & List<String>> T transform(String input) throws
IOException;
}
My Implementation Class A is shown as below:
public Class A implements Transformer{
....
....
@Override
public <T extends String & List<String>> T transform(String input) throws IOException {
String response = "a";
return response; // compilation error "Incompatible Types: Required T but found java.lang.String"
}
}
What I want to have : The implementation class should be able to pass a String input and return type can be String or a List. The implementation class is totally given freedom to choose either of the return types.
Question: 1. Why is the compilation error "Incompatible Types: Required T but found java.lang.String" is showing up?