February 2014
Beginner
1248 pages
62h 25m
English
In this section, we introduce a powerful generics concept known as wildcards. Let’s consider an example that motivates wildcards. Suppose that you’d like to implement a generic method sum that totals the numbers in a collection, such as an ArrayList. You’d begin by inserting the numbers in the collection. Because generic classes can be used only with class or interface types, the numbers would be autoboxed as objects of the type-wrapper classes. For example, any int value would be autoboxed as an Integer object, and any double value would be autoboxed as a Double object. We’d like to be able to total all the numbers in the ArrayList regardless of their type. For this reason, we’ll declare ...
Read now
Unlock full access