I have:
class Hammer Implements Part {
public String getName() { return name; }
public int getId() { return id; }
...
}
class Wrench implements Part {
public String getName() { return name; }
public int getId() { return id; }
...
}
interface Part {
String getName();
int getId();
}
I use a pre-created database manager written for Android SQLite, which returns a list of objects based on what I retrieve:
dataManager().getWrenchDao().getAll();
I cannot change how this function works.
Now I get both lists:
List<Wrench> wrenches = dataManager().getWrenchDao().getAll();
List<Hammer> hammers = dataManager().getHammerDao().getAll();
However, I want to fill this information with spinners (Spinners are drop-down lists in android).
loadSpinner(Spinner s, List<Part> data) {
...
data.ElementAt(i).getName();
data.ElementAt(i).getId();
...
}
loadSpinner(wrenchSpinner, wrenches);
But this gives me a casting error that you cannot change. Why doesn't Java allow me to do this? Wrenches have all the methods that Part do so, why can't I use it in something that it implements and uses?
Error:
The method loadSpinner(Spinner, List<Part>) in the type NewActivity is not applicable for the arguments (Spinner, List<Wrench>)
source
share