Which concept allows generic collections to interoperate with java code that defines collections that use raw types?
A.
bytocode manipulation
B.
casting
C.
autoboxing
D.
auto-unboxing
E.
type erasure
Explanation:
Autoboxing, introduced in Java 5, is the automatic conversion the Java compiler makes between the primitive (basic) types and their corresponding object wrapper classes (eg, int and Integer, double and Double, etc). The underlying code that is generated is the same, but autoboxing provides a sugar coating that avoids the tedious and hard-to-read casting typically required by Java Collections, which can not be used with primitive types.
type erasure – the Java compiler interprets
the generics specified in the source code and replaces the generic code with concrete types.
E. type erasure
answer C
note that “that use raw types?”
the correct answer is E, type erasure is one of the main advantage of generic at compile time.
type erasure
E.
E is correct. @[email protected]: Raw types != primitives
E.
OCA/OCP Java SE 7 Programmer I & II Study Guide (Kathy Sierra, Bert Bates)
637. Generic Types (OCP Objectives 4.1 and 4.3)
Through a process called “type erasure,” the compiler does all of its verifications on
your generic code and then strips the type information out of the class bytecode.
At runtime, ALL collection code—both legacy and new Java 5 code you write using generics—
looks exactly like the pregeneric version of collections. None of your typing information exists
at runtime. In other words, even though you WROTE
List myList = new ArrayList();
by the time the compiler is done with it, the JVM sees what it always saw before Java 5 and generics:
List myList = new ArrayList();
List myList = new ArrayList ();
by the time the compiler is done with it, the JVM sees what it always saw before Java 5 and generics:
List myList = new ArrayList();
wtf…. I’m trying to put the Less-than and Greater-than signs with Integer within
but the post delete them
List Less-than sign Integer Greater-than sign myList = new ArrayList Less-than sign Integer Greater-than sign ();
by the time the compiler is done with it, the JVM sees what it always saw before Java 5 and generics:
List myList = new ArrayList();
e