February 2014
Beginner
1248 pages
62h 25m
English
The code in methods testPushDouble and testPushInteger is almost identical for pushing values onto a Stack<Double> or a Stack<Integer>, respectively, and the code in methods testPopDouble and testPopInteger is almost identical for popping values from a Stack<Double> or a Stack<Integer>, respectively. This presents another opportunity to use generic methods. Figure 20.10 declares generic method testPush (lines 24–35) to perform the same tasks as testPushDouble and testPushInteger in Fig. 20.9—that is, push values onto a Stack<T>. Similarly, generic method testPop (Fig. 20.10, lines 38–58) performs the same tasks as testPopDouble and testPopInteger in Fig. 20.9—that is, pop values off a Stack<T> ...
Read now
Unlock full access