Reputation: 68
I want to know if I can improve my class, by avoiding the second V in the declaration of my class. Somehow it looks awful.
public abstract class TreeElementAction<T extends TreeNode<V>, V> {
protected abstract boolean actFor(@Nullable T element);
public void forEachElementInTree(@Nonnull T rootNode) {
requireNonNull(rootNode);
actFor(rootNode);
Collection<T> children = (Collection<T>) rootNode.getChildren();
for (T treeNode : children) {
forEachElementInTree(treeNode);
}
}
}
Upvotes: 0
Views: 31
Reputation: 140309
Unless you require V
in any of the concrete implementations of this class, you can just drop the type variable, as @PeterLawrey has suggested, and replace it with an unbounded wildcard in TreeNode<V>
:
public abstract class TreeElementAction<T extends TreeNode<?>> {
Upvotes: 1