Generics

A

Create a generic class Interval that has a start point and an stop point. The stop point must be larger or equal to than the start point. As examples, the interval [3, 5] is legal and the interval [8, 5] is illegal. The interval class must have the methods getStart(), getStop(), toString(), and getLength().

B

Create a generic method in a non-generic class that can find the maximum of three parameters. As examples maximum(3,4,1) returns 4 and maximum(4,88,101) returns 101.

C

Make is possible for the Interval from Exercise A to have start and stop points of different types, e.g., an int and a double. As examples [8.4, 30] is legal and [10, 4.4] is illegal.

D

In the group, list both the advantages and disadvantages of generics classes and methods.

Extra Assignments

E1

Consider your project. Do you have classes in the project that can be made more reuseable by making them generic?

E2

Exercise 6 on page 805 in the book. Create a priority queue using a generic class.