Common Features in the Overloaded printArray Methods

Study each printArray method. The array element type appears in each method’s header (lines 22, 32 and 42) and for-statement header (lines 25, 35 and 45). If we were to replace the element types in each method with a generic name—T by convention—then all three methods would look like the one in Fig. 20.2. It appears that if we can replace the array element type in each of the three methods with a single generic type, then we should be able to declare one printArray method that can display the String representations of the elements of any array that contains objects. The method in Fig. 20.2 is similar to the generic printArray method declaration you’ll see in Section 20.3. The one shown here ...

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.