The document discusses using the Java Collections Framework in a class, including examining one method definition from each class to understand how they work rather than treating them as black boxes. It notes the version being used includes type parameters, also called generics, which were added in Java 5.0 to avoid downcasting and find errors at compile time rather than runtime. It also mentions boxing, unboxing, and enhanced for statements were added to complement generics when working with primitive values in collections that require wrapper class objects.
The document discusses using the Java Collections Framework in a class, including examining one method definition from each class to understand how they work rather than treating them as black boxes. It notes the version being used includes type parameters, also called generics, which were added in Java 5.0 to avoid downcasting and find errors at compile time rather than runtime. It also mentions boxing, unboxing, and enhanced for statements were added to complement generics when working with primitive values in collections that require wrapper class objects.
The document discusses using the Java Collections Framework in a class, including examining one method definition from each class to understand how they work rather than treating them as black boxes. It notes the version being used includes type parameters, also called generics, which were added in Java 5.0 to avoid downcasting and find errors at compile time rather than runtime. It also mentions boxing, unboxing, and enhanced for statements were added to complement generics when working with primitive values in collections that require wrapper class objects.
lthough the primary emphasis is on using the Java Collections Framework, the
framework classes are not
treated simply as “black boxes.” For each such class, the heading and field are provided, and one method definitio is dissected. This exposition takes away some of the mystery that would otherwise surround the class, and allows students to see the eff ciency and succinctness of professionals’ code. The version of the Java Collections Framework we will be working with includes type parameters. Type parameters, sometimes called “generic types,” “generics,” or “templates,” were added to the Java language starting with Java 5.0. With type parameters, there is no need to downcast the return value from a collection, and many errors can be detected at compile-time that previously were discoverable only at run-time. To complement generics, three other features have been added: boxing, unboxing, and an enhanced for statement. The elements in generic collections must be objects, often from a wrapper class such as Integer. If a primitive value appears where a collection method requires a wrapper element as an argument, boxing automatically converts the primitive value to the corresponding wrapper element. C