I have an interface called IUploader<T>
which has many abstract methods. One of them is List<UploadErrors> getErrors()
method. The behaviour is given below.
interface IUploader<T> {
T parse();
// some more abstract and default methods
List<UploadErrors> getErrors();
}
void someMethod(IUploader uploader) {
// calling other methods of IUploader implementations
List errors = uploader.getErrors(); // Problem - Getting List without type parameter
}
<T> void someMethod(IUploader<T> uploader) {
// calling other methods of IUploader implementations
List<UploadErrors> errors = uploader.getErrors(); // Works fine
}
The problem here is, when I give type parameter for IUploader
in someMethod()
, I'm getting the local variable of getErrors()
method as List<UploadErrors>
. But without type parameter, I'm getting simply List
. There is no relation between <T>
and UploadErrors
, but why this behaviour? The reason I have added Intellij IDEA is because, when I do Alt+Enter
to "Introduce local variable", I get this two types. I have not tried in other IDEs. Please help me to understand this behaviour.