Question: Objective The objective of this lab is exploring Java Generics in more details. After completing the lab, you should be confident to undertake any project/assignment

 Objective The objective of this lab is exploring Java Generics in

Objective The objective of this lab is exploring Java Generics in more details. After completing the lab, you should be confident to undertake any project/assignment involving Java generics. Also, this lab will teach you how you can convert any non-generic method into a generic one. Tasks Consider the following code snippet, where the printArray() method is used to print out arrays of different types: Integer [] intArray = {1, 2, 3, 4, 5 }; Double [] doubArray = {1.1, 2.2, 3.3, 4.4}; Character [] charArray = {'H','E','1', 'L', 'O' }; String [] strArray = { "once", "upon", "a", "time" }; printArray (intArray); printArray (doubArray); printArray (charArray); printArray (strArray); You will program variations of this functionality, among others, to help solidify your understanding of how types operate in Java. Requirements Write a Java program named Lab2.java (important) with a main method and implementations of the following: 1. A static printArrayNonGen() method with an array of Objects as parameter. 2. A static printArray () method using method overloading. Implement four versions of printArray (), one for each array type. 3. Implement a single static method printArrayGen() that uses the generic programming technique to support all 4 array types and maintain type safety. 4. Using non-generic techniques, implement a static method getMax () that takes an array of type Comparable and returns the maximum element in the array. (i.e. "public static Comparable getMax (Comparable [] anArray)"). 5. Using the generic techniques to specify super-class relationships, implement a type safe version of the method in 4 named getMaxGen()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!