Bounded Types
This lesson discusses bounded types in Java's generics.
We'll cover the following...
Question # 1
What are bounded type parameters?
When you want to restrict the types that can be used as type arguments in a parameterized type, you can do so by bounding the type parameter. For instance, say you are designing a specialized collection class that should only contain numbers. The type parameter can be bounded by the Number
class to ensure that consumers of your specialized collection can never add items which aren't of type Number
or one of its subclass. Let's see how you'll do it without ...