KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > spoon > examples > stack > src > Stack


1 package spoon.examples.stack.src;
2
3 import java.util.List JavaDoc;
4 import java.util.Vector JavaDoc;
5
6 import spoon.examples.stack.annotation.Bound;
7
8 /**
9  * As shown below, our stack class is a typical stack annotated by a
10  * {@link spoon.examples.stack.annotation.Bound} annotation.
11  */

12 @Bound(max = 5)
13 public class Stack<T> {
14
15     List JavaDoc<T> elements = new Vector JavaDoc<T>();
16
17     public void push(T element) {
18         elements.add(0, element);
19     }
20
21     public T pop() {
22         return elements.remove(0);
23     }
24
25     public static void main(String JavaDoc[] args) {
26         try {
27             Stack<Stack> s = new Stack<Stack>();
28             s.push(s);
29             System.out.print(".");
30             s.push(s);
31             System.out.print(".");
32             s.push(s);
33             System.out.print(".");
34             s.push(s);
35             System.out.print(".");
36             s.push(s);
37             System.out.print(".");
38             s.push(s);
39             System.out.print(".");
40             s.push(s);
41             System.out.print(".");
42         } catch (Exception JavaDoc e) {
43             System.out.flush();
44             System.err.println("Exception " + e.getClass().getSimpleName());
45         }
46     }
47 }
48
Popular Tags