0

I have a problem with creating a Queue object.I dont know what is wrong.

My code:

import java.util.*;
public class Demo {
    public static void main(String[] args) {

        Queue<Integer> q = new LinkedList<Integer>();


    }
}

Compiler error:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: The type LinkedList is not generic; it cannot be parameterized with arguments

4
  • I am not getting any Compile time errors for this code on eclipse. Commented Apr 14, 2013 at 19:53
  • 1
    This is odd - LinkedList IS generic. Do you have another LinkedList defined/imported somewhere? Try Mohammad's solution below to force the compiler to use the correct LinkedList. Commented Apr 14, 2013 at 19:54
  • It is something related with your library..Use java.util.ArrayList Commented Apr 14, 2013 at 19:54
  • I crated a new project now its working. Commented Apr 14, 2013 at 19:56

1 Answer 1

1

might be a name conflict (see if you have a class named LinkedList somewhere in your default package)

Try this -

 Queue<Integer> q = new java.util.LinkedList<Integer>();
Sign up to request clarification or add additional context in comments.

4 Comments

But why i need to do this?.If you see code given in question import is already being done
Can't say if OP has a class Named LinkedList somewhere
@Algorithmist: I suspect there's another class in the default package with the name LinkedList. But it's not clear what you mean by "But why I need to do this" - are you actually the original poster? If so, please don't use multiple accounts.
@JonSkeet I am not the poster of this question :). Now i am not able to edit my post. I used "I" mainly because i tried to write the same code on my eclipse after seeing this question and got no errors.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.