Generics and Collections Flashcards
When using primitive operands, how does the == operator determine equality?
By comparing their underlying values
Which phrase describes the compiler replacing all generic parameters with existing types that match the required bounds or Object if the type parameter is unbounded?
type erasure
Which interface provides a natural order of elements for a Map?
SortedMap
What is a raw type?
A traditional collection that uses Object to store its elements.
Which four methods will return the first element in a Deque?
pop, poll, peek, remove,
Also removeFirst, pollFirst, peekFirst, element, getFirst
Which limitation on instantiation is a direct result of type erasure?
Generic parameters cannot be directly instantiated.
Which keyword is used in conjunction with the ? character to specify a lower bound for allowable data types?
super
Which type of collection cannot contain duplicate elements?
Set
Which conversion between raw and parameterized types will generate an unchecked conversion warning?
Conversion from raw type to parameterized type
When is the diamond operator used with a constructor to infer a type for a generic parameter?
The type is explicitly specified in the variable declaration.
Which keyword is used in conjunction with the ? character to specify an upper bound for allowable data types?
extends
Which interface should be implemented to sort elements in an order other than the default order in collection?
Comparator
Which keyword applies to either an interface or a superclass when bounding generic parameters?
extends
Which operator indicates an empty set of type parameters using type inference?
Diamond (<>) operator
Which conversion does a compiler automatically provide between primitive types and corresponding object wrapper classes?
Autoboxing
When using reference operands, how does the == operator determine equality?
By comparing their object references
What is the primary storage and retrieval mechanism for a Map?
name/value pairs
Which interface should be implemented by objects that can be sorted as elements in a collection?
Comparable
Which conversion between raw and parameterized types will NOT generate an unchecked conversion warning?
Conversion from parameterized type to raw type
Which character indicates a wildcard for allowable data types?
?
What collection classes implement Deque and can be used to represent a LIFO stack?
ArrayDeque, ConcurrentLinkedDeque, LinkedBlockingDeque, LinkedList
These are preferred over Stack