Generics Basics (T, inference)
Learn generic type parameters T , why they give compile-time safety, and how the diamond operator infers types.
Why generics?
Generics add types to containers and utilities so the compiler can protect you. Benefits:
- Type safety — no accidental mix of types.
- No casts — cleaner code.
- Reusable — one class works for many types.
What is T?
T (type parameter) is a placeholder for a real type. When you write Box<String>, the compiler treats T as String inside that usage.
All lessons in this course
- Interfaces in Practice
- Generics Basics (T, inference)
- Generic Methods/Classes