Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Development For Dummies

Authors: Allen G. Taylor

1st Edition

978-0764507526

More Books

Students also viewed these Databases questions