Practice mode Java

Why does the declaration List<int> fail to compile in Java?

Correct answer C. Type arguments must be reference types

Explanation

A generic type argument must be a reference type, so a primitive such as int is not allowed. Generics are implemented by erasure, which treats type parameters as Object or their bound, and a primitive is not an Object. The usual solution is List, with autoboxing converting between int and Integer automatically.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.