Dayrvia
Jv

Java · Generics and unboxing · Practice questions

Try 2 questions on Java · Generics and unboxing, then read the explanations and review the related concepts.

Practice questions

Choose an answer and move to the next question. Grade the last one to see explanations and review links.

2 questions
Q1 Which conversion occurs in the last line?
List<Integer> xs = new ArrayList<>();
xs.add(4);
int x = xs.get(0);
Q2 Why can head accept a nonempty List<Double>?
static Number head(List<? extends Number> xs) {
    return xs.get(0);
}
Original practice questions written for Dayrvia.