Java Reference
In-Depth Information
represent the same type then use the same name; if they can be dis-
tinct types, then use different names.
If the nested type is an inner class, then the type variables of the outer
class declaration are accessible to it and can be used directly. For ex-
ample, an alternative design of the queue could use a non-generic inner
class to define cell objects:
class SingleLinkQueue<E> {
class Cell {
private Cell next;
private E element;
public Cell(E element) {
this.element = element;
}
public Cell(E element, Cell next) {
this.element = element;
this.next = next;
}
public E getElement() {
return element;
}
/* ... rest of Cell methods ... */
}
protected Cell head;
protected Cell tail;
public void add(E item) {
Cell cell = new Cell(item);
if (tail == null)
head = tail = cell;
else {
tail.setNext(cell);
tail = cell;
}
}
public E remove() {
 
Search WWH ::




Custom Search