Java Generics, Enums, and Autoboxing Flashcards
6 cards from real SCJP practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 Java Generics, Enums, and Autoboxing flashcards as text
What does `Collections.emptyList()` return and why is it preferred?
Answer: An immutable, type-safe empty List singleton
`Collections.emptyList()` returns a shared, immutable, type-safe empty List, avoiding null checks and unnecessary object creation.
What is the `ordinal()` method in a Java enum?
Answer: Returns the zero-based position of the constant in the enum declaration
`ordinal()` returns the position of the enum constant in its declaration order, starting from 0.
Which of the following statements about Java generics and arrays is true?
Answer: Generic arrays cannot be created directly due to type erasure
You cannot directly create generic arrays (`new T[10]`) because type erasure removes the type information needed for array creation at runtime.
What is the purpose of the `@SuppressWarnings("unchecked")` annotation in Java?
Answer: To suppress compiler warnings about unchecked or unsafe generic operations
`@SuppressWarnings("unchecked")` tells the compiler to suppress warnings generated by unchecked casts or raw type usage in generics.
In Java, which method retrieves an enum constant by its name string?
Answer: EnumType.valueOf(name)
`EnumType.valueOf("CONSTANT_NAME")` returns the enum constant with the specified name, throwing `IllegalArgumentException` if not found.
What is the effect of assigning an `int` to an `Integer` variable in Java?
Answer: Autoboxing converts the int to an Integer automatically
Autoboxing automatically converts the primitive `int` to an `Integer` wrapper object when assigned to an `Integer` variable.
How this page was made: written with AI tools and published by Nathan Beja, founder of Practice Test Geeks, who is responsible for its content. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Not reviewed by a subject-matter expert. Editorial policy