- Esecutori
-
Impara
Impara Python Esempi eseguibili, NumPy, pandas e altro Impara l'IA / Machine LearningReti neurali, ML e LLM da zero Impara C e C++ Puntatori, memoria, STL e C++ moderno Impara C#Fondamenti, OOP, LINQ, async ed esercizi .NET Impara MatplotlibGrafici a linee, barre, dispersione e torta con visualizzatori Impara RustOwnership, trait, gestione degli errori e thread Impara GoSlice, interfacce, goroutine e canali Algoritmi Python Ricerca, ordinamento, ricorsione e visualizzazioni O(n) Algoritmi C e C++ Confronta le implementazioni in C e C++ Programmazione per bambini Impara a programmare giocando!
- QuizNuovo
- SfideNuovo
- Per docentiNuovo
- Aggiornamenti
- Offrimi un caffè
Quiz di Java: Generics
This Java quiz goes beyond List<String> and into the questions interviewers like to ask about generics. You will meet type erasure, invariance, extends and super wildcards, raw types and generic methods.
Domanda di esempio
Domanda 1 di 10What does this print?
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) {
List<String> a = new ArrayList<>();
List<Integer> b = new ArrayList<>();
System.out.println(a.getClass() == b.getClass());
}
}
Mostra la risposta
B. true Generic type arguments are erased at compile time, so at runtime both objects are plain ArrayList instances with the same class. List<String> and List<Integer> only differ for the compiler.
Cosa copre questo quiz
- Type erasure and what it means at runtime
- Why
List<String>is not aList<Object>, while arrays are covariant - Bounded types like
<T extends Comparable<T>> - Wildcards:
? extendsfor reading,? superfor writing (PECS) - Raw types, type inference and what generics cannot do
Domande frequenti
Serve un account?
No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.
Posso rifarlo?
Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.