LearnFrenzy
Sign in Take a free test

Object Class and Wrapper Classes · Find the Error · Question 1

Error: a primitive type as a generic argument Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

The program below does not compile. Which statement correctly describes the problem?

Main.java
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<int> marks = new ArrayList<>();
        marks.add(90);
        System.out.println(marks);
    }
}
  • A ArrayList needs a size
  • B Generic type arguments must be reference types; use List<Integer> and let autoboxing convert the ints Correct
  • C add cannot take 90
  • D List must be imported twice
Correct Answer: Option B

javac: "unexpected type – required: reference, found: int".

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links