OnJava8-Examples/generics/SimpleQueue.java
2015-04-20 15:36:01 -07:00

13 lines
375 B
Java

//: generics/SimpleQueue.java
// A different kind of container that is Iterable
import java.util.*;
public class SimpleQueue<T> implements Iterable<T> {
private LinkedList<T> storage = new LinkedList<T>();
public void add(T t) { storage.offer(t); }
public T get() { return storage.poll(); }
public Iterator<T> iterator() {
return storage.iterator();
}
} ///:~