13.9. Summary
In this chapter you have learned the essentials of how generic types are defined and used. In the next chapter you'll see how the java.util package provides you with an extensive range of standard generic types you can use in your programs. The important points you have seen in this chapter include:
A generic type, which is also referred to as a parameterized type, defines a family of classes or interfaces using one or more type parameters. Container classes are typically defined as generic types.
The argument you supply for a type parameter can be a class type or an interface type. It cannot be a primitive type.
You can limit the scope of type arguments for a given type parameter by specifying one or more bounds for the parameter using the extends keyword. The first bound can be a class or interface type; the second and subsequent bounds must be interface types.
You define a specific type from a generic type by supplying a type argument for each type parameter.
All types produced from a given generic type share the same run-time type.
A parameterized method defines a family of methods using one or more independent type parameters.
A parameterized method can be a member of an ordinary class type or a generic type.
You can use wildcards as type arguments in a parameterized type in situations where there is no dependency on a specific type.
You can constrain a wildcard type argument with either an upper bound that you specify using the extends keyword or with a lower bound ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access