2Chapter 20 Generic Classes and Methods: A Deeper Look
Self-Review Exercises
20.1 State whether each of the following is true or false. If false, explain why.
a) A generic method cannot have the same method name as a nongeneric method.
b) All generic method declarations have a type-parameter section that immediately pre-
cedes the method name.
c) A generic method can be overloaded by another generic method with the same method
name but different method parameters.
d) A type parameter can be declared only once in the type-parameter section but can ap-
pear more than once in the method’s parameter list.
e) Type-parameter names among different generic methods must be unique.
f) The scope of a generic class’s type parameter is the entire class except its static mem-
bers.
20.2 Fill in the blanks in each of the following:
a) and enable you to specify, with a single method declaration, a set
of related methods, or with a single class declaration, a set of related types, respectively.
b) A type-parameter section is delimited by .
c) A generic method’s can be used to specify the method’s argument types, to
specify the method’s return type and to declare variables within the method.
d) In a generic class declaration, the class name is followed by a(n) .
e) The syntax specifies that the upper bound of a wildcard is type T.
Exercises
NOTE: Solutions to the programming exercises are located in the ch20solutions folder.
Each exercise has its own folder named ex20_## where ## is a two-digit number represent-
ing the exercise number. For example, exercise 20.4’s solution is located in the folder
ex20_04.
20.3 (Explain Notation) Explain the use of the following notation in a Java program:
public class Array<T> { }
20.7 (Generic isEqualTo Method) Write a simple generic version of method isEqualTo that
compares its two arguments with the equals method and returns true if they’re equal and false
© 2018 Pearson Education, Inc., 330 Hudson Street, NY NY 10013. All rights reserved.