Methods testPushInteger and testPopInteger

Method testPushInteger (lines 62–73) invokes Stack method push to place values onto integerStack until it’s full. Method testPopInteger (lines 76–96) invokes Stack method pop to remove values from integerStack. Once again, the values are popped in lastin, first-out order. During erasure, the compiler recognizes that the client code in method testPopInteger expects to receive an int when method pop returns. So the compiler inserts an Integer cast, as in

popValue = (Integer) stack.pop();

The value assigned to popValue will be unboxed from the Integer object returned by pop.

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.