There is this method (abbreviated) in the project I'm working on:
public <T> T query(
final Extractor<T> extractor, final List result) {
//...
return extractor.extract(result)
//...
}
with the Extractor defined as:
public interface Extractor<T> {
T extract(List<Map<String, Object>> result);
}
In Eclipse there isn't any error but IntelliJ refuses to compile the class with Incompatible types: Required: T Found: Object
, the only way to is if I cast the return value to T or return Object instead and I can't figure out why it is failing.
I'm getting the same error in Eclipse.
It is probably caused by using the raw List
type.
Changing the signature of the query
method to:
public <T> T query(final Extractor<T> extractor, final List<Map<String, Object>> result)
fixes it.
You need to add type argument to the parameter:
query(final Extractor<T> extractor, final List<Map<String, Object>> result){
The error message because of type mismatch(Raw Type). Here is what docs say about raw type:
Raw types show up in legacy code because lots of API classes (such as the Collections classes) were not generic prior to JDK 5.0. When using raw types, you essentially get pre-generics behavior — a Box(in your case List) gives you Objects. For backward compatibility, assigning a parameterized type to its raw type is allowed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With