In my application, I have a Board. A Board consists of cell. Each cell has an int value. There are few types of Boards that will extend Board. Each type of Board will represent the cells differently. For example, one would use a List and anothr will use a Tree.
So this is what is tried:
public abstract class Board<T> {
T<Cell> cells; //error - The type T is not generic; it cannot be parameterized with arguments <Cell>
protected abstract void setValues(T<Integer> values);
}
Unfortunately, I can't make T a generic type. How do I implement that?
T extends Collectionin your class signature? That way you can useListorTree? Not too confident in my suggestion, I'd like critique if necessary.T? Usually, you'd just nest the parameterized type in the generic declaration forBoard, but it doesn't make sense to have an unrestrictedTparameter that you then expect to be generic; what ifTisInteger? Furthermore, is this a case where just subclassingBoardwould make more sense than having a generic parameter on it? After all, the client will have to be aware of the differences if it's providing the representation for them.setValuesmethod, how the board should internally access itscells, and what typesTcan be (when you say "Tree", do you mean aTreeSet? If it always is aCollection, then this is fairly trivial...)Tto be generic?