2

I am trying to complete a JCF array list, and it compiled just fine 30 minutes ago, but now I am receiving the error "The type ArrayList is not generic; it cannot be parameterized with arguments ". I have tried a few things to figure it out, but I am at a loss. Here is the code:

import java.util.*;

/**
 * Class to test the java.util.ArrayList class.
 */
public class Main
{

    public static void main(String[] args)
    {
        Main myAppl = new Main();

    }

    public Main()
    {
        ArrayList<Integer> numbers = new ArrayList<Integer>();

        //list creation
        for (int i = 0; i < 10; i++)
            numbers.add((int) (Math.random() * 100));

        System.out.println("List of numbers:");
        System.out.println(numbers);

        Scanner in = new Scanner(System.in);
        System.out.print("Please, enter an int value: ");
        int x = in.nextInt();

        if (numbers.contains(x))
            System.out.println("Found!");
        else
            System.out.println("Not found!");
    }
}
3
  • 2
    What version of Java are you compiling with? Commented Feb 27, 2014 at 4:49
  • 3
    I suspect you've some other ArrayList class in your classpath. Replace import java.util.*; with java.util.ArrayList, and I'm sure it would certainly work. Commented Feb 27, 2014 at 4:50
  • What does System.out.println(numbers.getClass()); output? Commented Feb 27, 2014 at 4:55

3 Answers 3

9

2 possibilities:

  1. You are using some mysterious ArrayList from a 3rd party package rather than java.util.ArrayList; or

  2. Your compiler settings is pre-1.5 or your effective JDK is pre-1.5 so generic wasn't available.

Sign up to request clarification or add additional context in comments.

1 Comment

"some mysterious ArrayList from a 3rd party package" or perhaps in his own package
7

Try changing your class name to a different one. i.e. other than ArrayList or main.

1 Comment

Great anticipation.
4

Assuming you're using (and targeting) a version greater then or equal to 1.5 then you must have a class named ArrayList that shadows the one you want; you should use

// If your compiler settings are correct.
java.util.ArrayList<Integer> numbers = new java.util.ArrayList<Integer>();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.