Skip to main content
CMP175
Unit 8 of 8
4 Hours

Generics

4 topics4 videos5 assignments
8.1&8.2

Advantages of Using Generics and Generic Classes

Lecture2 assignments

Assignment 1

Why Generics Matter

Assignment BriefDue: Complete before Topic 8.3 (Generic Methods)

Why Generics Matter

Explain the benefits of generics in Java, focusing on type safety, code reusability, and reduced type casting. Include at least two examples where generics prevent runtime errors.

Assignment 2

Implement a Generic Box Class

Assignment BriefDue: Complete before Topic 8.3 (Generic Methods)

Implement a Generic Box Class

Create a generic class Box<T> with set(T value) and get() methods. Test it with String, Integer, and Double values to demonstrate type-safe reuse.

8.3

Generic Methods

Lecture1 assignment

Assignment

Create and Use Generic Methods

Assignment BriefDue: Complete before Topic 8.4 (Generic Constructors)

Create and Use Generic Methods

Write a utility class containing a generic method to print any array and another generic method to return the maximum of three comparable values.

8.4

Generic Constructors

Lecture1 assignment

Assignment

Practice Generic Constructors

Assignment BriefDue: Complete before Topic 8.5 (Polymorphism in Generics)

Practice Generic Constructors

Create a class with a generic constructor that accepts different data types and stores or prints them. Instantiate the class with at least three different argument types.

8.5

Polymorphism in Generics

Lecture1 assignment

Assignment

Generics with Polymorphism

Assignment BriefDue: Complete as a consolidation of Unit 8

Generics with Polymorphism

Write a Java program using a generic method with wildcard bounds (for example List<? extends Number>) and demonstrate how polymorphism works with different numeric wrapper types.