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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started