Compiler Warnings

Figure 20.12 shows the warning messages generated by the compiler when the file RawTypeTest.java (Fig. 20.11) is compiled with the -Xlint:unchecked option, which provides more information about potentially unsafe operations in code that uses generics. The first warning in Fig. 20.11 is generated for line 17, which assigned a raw-type Stack to a Stack<Integer> variable—the compiler cannot ensure that all objects in the Stack will be Integer objects. The next warning occurs at line 19. The compiler determines method testPush’s type argument from the Double array passed as the third argument, because the second method argument is a raw-type Stack variable. In this case, Double is the type argument, so the compiler expects a

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.