Today I came across some code that turned out to be dubious. Here's a simplified example (not realistic).
public interface IListable {
public ArrayList getFirstNThings(int n);
public ArrayList getLastNThings(int n);
}
Then there is such a constructor:
public GroceryList implements IListable {
private ArrayList<GroceryItem> groceries;
public GroceryList() {
this.groceries = new ArrayList<GroceryItem>();
}
public ArrayList<GroceryItem> getFirstNThings(int n) {
ArrayList<GroceryItem> firstNThings = new ArrayList<GroceryItem>();
for (int i=0; i < n; i++) {
firstNThings.add(this.groceries.get(i));
}
return firstNThings
}
public ArrayList<GroceryItem> getLastNThings(int n) {
ArrayList<GroceryItem> lastNThings = new ArrayList<GroceryItem>();
for (int i=this.groceries.size(); i < this.groceries.size()-n; i--) {
lastNThings.add(this.groceries.get(i-1);
}
return lastNThings;
}
}
Ignore any implementation problems you may find in this (I also found some). What I get is that the interface does not use any general parameter type for ArrayList (e.g. ArrayList <?>), But the developer of the interface method does (i.e. ArrayList <GroceryList>). Other developers can return ArrayLists with any other type parameters, no?
, : ? -? ? ? , , , , ?