Java Reference
In-Depth Information
9. When calling a generic method, you need not instantiate the type variables.
782
783
10. Type variables can be constrained with bounds.
11. The virtual machine works with raw types, not with generic classes.
12. The raw type of a generic type is obtained by erasing the type variables.
13. To interface with legacy code, you can convert between generic and raw types.
REVIEW EXERCISES
΢ Exercise R17.1. What is a type variable?
΢ Exercise R17.2. What is the difference between a generic class and an
ordinary class?
΢ Exercise R17.3. What is the difference between a generic class and a
generic method?
΢ Exercise R17.4. Find an example of a non-static generic method in the
standard Java library.
΢΢ Exercise R17.5. Find four examples of a generic class with two type
parameters in the standard Java library.
΢΢ Exercise R17.6. Find an example of a generic class in the standard library
that is not a collection class.
΢ Exercise R17.7. Why is a bound required for the type variable T in the
following method?
<T extends Comparable> int binarySearch(T[]
a, T key)
΢΢ Exercise R17.8. Why is a bound not required for the type variable E in the
HashSet<E> class?
΢ Exercise R17.9. What is an ArrayList<Pair<T, T>> ?
Search WWH ::




Custom Search