Java Reference
In-Depth Information
Empty: true
Full: false
Adding A
Adding B
Adding C
Adding D
Adding E
Empty: false
Full: true
Removing A
Empty: false
Full: false
Adding F
Removing B
Removing C
Removing D
Removing E
Removing F
Empty: true
Full: false
Type Parameter Bounds
List<E> 's E typeparameterand Map<K, V> 's K and V typeparametersareexamples
of unbounded type parameters .Youcanpassanyactualtypeargumenttoanunbounded
type parameter.
It is sometimes necessary to restrict the kinds of actual type arguments that can be
passed to a type parameter. For example, you might want to declare a class whose in-
stancescanonlystoreinstancesofclassesthatsubclassanabstract Shape class(such
as Circle and Rectangle ).
Torestrictactualtypearguments,youcanspecifyan upper bound ,atypethatserves
as an upper limit on the types that can be chosen as actual type arguments. The upper
bound is specified via reserved word extends followed by a type name.
Forexample, ShapesList<E extends Shape> identifies Shape asanupper
bound. You can specify ShapesList<Circle> , ShapesList<Rectangle> ,
and even ShapesList<Shape> , but not ShapesList<String> because
String is not a subclass of Shape .
Search WWH ::




Custom Search