February 2014
Beginner
1248 pages
62h 25m
English
Now, let’s consider the application (Fig. 20.9) that uses the Stack generic class (Fig. 20.7). Lines 12–13 in Fig. 20.9 create and initialize variables of type Stack<Double> (pronounced “Stack of Double”) and Stack<Integer> (pronounced “Stack of Integer”). The types Double and Integer are known as the Stack’s type arguments. The compiler uses them to replace the type parameters so that it can perform type checking and insert cast operations as necessary. We’ll discuss the cast operations in more detail shortly. Lines 12–13 instantiate doubleStack with a capacity of 5 and integerStack with a capacity of 10 (the default). Lines 16–17 and 20–21 call methods testPushDouble (lines 25–36), testPopDouble ...
Read now
Unlock full access