Thompson Rivers University
Question 2
Lab 4 Collections - SM 2025Take the original generic Pair<F, S> class and change it so that both stored values share one type parameter <T>. In practice, this means rewriting the class so it always stores two values of the same type.
Why This Matters
A generic class with two type parameters (<F, S>) lets you mix types, but sometimes you want to force both elements to be the same type. By using a single type parameter <T>:
You simplify the class design
You guarantee that
firstandsecondalways have the same data type
Original Pair Definition for Reference
Below is the original Pair<F, S> (from the slides) so you do not have to open them. We will modify this into a new class called Pair2<T>.
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 54 more lessons in Thompson Rivers University.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.