Question: PART A. Write generic methods min and max, each of which accepts two parameters and returns the smaller and larger, respectively. Then use those methods

PART A.

Write generic methods min and max, each of which accepts two parameters and returns the smaller and larger, respectively. Then use those methods on the Integer type. These methods are currently not setup for generics, but for Strings. Make sure you change them into proper generic methods, so change out the "String" into AnyType that extends Comparable

public static String min(String a, String b) {

// TODO Convert this method to properly use Anytype and Comparable, then return the appropriate thing

return null;

}

public static String max(String a, String b) {

// TODO Convert this method to properly use Anytype and Comparable, then return the appropriate thing

return null;

} PART B. Write generic method min, which accepts an array and returns the smallest item. Then use the method on the String type. Similar to the methods above, switch out the "String" for proper generics

public static String min(String [] a) {

// TODO Convert this method to properly use Anytype and Comparable, then return the appropriate thing

return null;

}

I am having difficulty understanding generics and how to implement them. Please include an explanation.

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!