Java Reference
In-Depth Information
if (head == null)
return null;
Cell cell = head;
head = head.getNext();
if (head == null)
tail = null; // empty queue
return cell.getElement();
}
/* ... rest of methods ... */
}
This time the element type of the cell is directly tied to the element type
of the queue that it is in, and there is no need to declare Cell to be a
generic class.
If you do choose to use generic inner classes, a type variable in the inner
class hides any type variable with the same name in the outer class and,
as always, hiding should be avoided.
Deeply nesting types is even more of a problem when the nested types
are generic. Both nested types and generic types add an extra degree
of complexity to programs, and their combination can greatly compound
that complexity.
 
Search WWH ::




Custom Search