โ† All 1Z0-819 Flashcard Decks

Generics & Type Inference Flashcards

7 cards from real 1Z0-819 practice questions. Tap to flip, then mark Knew It or Still Learning โ€” missed cards come back until you master them.

Read the first 7 Generics & Type Inference flashcards as text
  1. What does type erasure mean in the context of Java generics?

    Answer: Generic type parameters are converted to their bounds (or Object) in compiled bytecode

    Type erasure means the compiler removes generic type information during compilation, replacing type parameters with their bounds or Object in the bytecode to maintain backward compatibility.

  2. Which of the following correctly declares a generic method in Java?

    Answer: public T getValue() { return null; }

    A generic method must declare its type parameter(s) in angle brackets before the return type, as in public T getValue().

  3. What does the diamond operator <> accomplish when used in Java?

    Answer: Instructs the compiler to infer the type parameter from the surrounding context

    The diamond operator <> tells the compiler to infer the generic type argument from the left-hand side or context, reducing verbosity in object creation expressions.

  4. Which statement about using raw types in Java is TRUE?

    Answer: Raw types bypass generic type checking and can lead to ClassCastException at runtime

    Raw types bypass the compiler's generic type safety checks, potentially leading to ClassCastException at runtime when incompatible types are inserted or retrieved.

  5. Given: List strList = new ArrayList<>(); Which assignment is valid?

    Answer: List extList = strList;

    List accepts a List because it is an upper-bounded wildcard; generic types are invariant, so all Object-based assignments are compile errors.

  6. Which of the following creates an illegal parameterized array in Java?

    Answer: List[] arr = new ArrayList[5];

    Java does not allow creation of arrays of parameterized types such as new ArrayList[5] because it would undermine type safety due to array covariance.

  7. What is the primary benefit of using generics over using Object as a parameter type?

    Answer: Generics provide compile-time type safety and eliminate the need for explicit casting

    Generics enforce type safety at compile time, removing the need for explicit casts and preventing ClassCastException that could occur when using raw Object-based collections.