java
Declare a generic interface called Pair that takes two type parameters K and V. This interface has two methods getKey that returns a value of type K, and getValue that returns a value of type V.
Write a class OrderedPair implementing the Pair interface. The class has two instance variables which are key (of type K) and value (of type V). Define the constructor of the class OrderedPair that initializes the instance variables.
In a class named Util, define a generic method, compare, which compares two Pair objects. Based on equals method inherited from the Object class, returns true if the keys and values of the two pairs are equal.
Test your compare method.
Write and test a generic method countGreaterThan that receives an array from any type that implements the Comparable interface and a parameter e of the same type. The method counts and returns the array elements that are greater than e.
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here