I have an abstract class in java:
private abstract class Importable<T> {
// ...
public abstract List<T> validateData(List<Path> paths);
public abstract void importData(List<T> data);
// ...
}
private static class MyImportable extends Importable<String>{
public List<String> validateData(List<Path> paths){
return // valid ArrayList<String>;
}
public void importData(List<String> data){
// do stuff with data
}
}
Now, if I do this:
public Importable importable;
// ...
importable = new MyImportable(); // MyImportable extends Importable<String>
calling this works:
importData(validateData(myPaths));
But I don't like the raw Importable
, so I added <?>
public Importable<?> importable;
doing so throws error:
The method importData(List<capture#5-of ?>) in the type ImportController.Importable<capture#5-of ?> is not applicable for the arguments (List<capture#6-of ?>)
while executing importData(validateData(myPaths));
and eclipse suggests me to cast to List<?>
, which did nothing to solve the problem
Is there something I'm missing?
EDIT: sorry if I wasn't clear, here is the actual usage
I will have many class that extends Importable with different types:
Importable importable;
switch(condition){
case 1:
importable= // Importable<MyType1>
break;
case 2:
importable= // Importable<MyType2>
// ....
}
importData(validateData(myPaths));
EDIT2:
I intentionally separate importData
and validateData
because some other class might want to validateData
only
If matters:
I'm using eclipse 4.3 w/ Java 8 on Windows 7 x64