I have the following classes
KeyValue.java
package test; public class KeyValue<T> { private String key; private T value; public String getKey() { return key; } public void setKey(String key) { this.key = key; } public T getValue() { return value; } public void setValue(T value) { this.value = value; } }
Reader.java
package test; public interface Reader<T> { <S extends T> S read(Class<S> clazz); }
Test.java
package test; import java.util.List; public class Test { public static void main(String[] args) { List<KeyValue<Object>> list = find(KeyValue.class, new Reader<KeyValue<Object>>() { @Override public <S extends KeyValue<Object>> S read(Class<S> clazz) { return null; } }); } public static <T> List<T> find(Class<T> targetClass, Reader<T> reader) { return null; } }
Here the call to the find(......) method find(......) does not work at compile time with an error message
The find (Class, Reader) method in the Test type is not applicable for arguments (Class, new Reader> () {}).
This method should return an object of type List<KeyValue<Object>> .
What is wrong with this design and how to fix it.
Thanks.
source share