I'm trying to make a linked list in Java, but there is an issue.
I thought that Link is in java.util.Link,but when I tried to do something like
Link nextLink;
Eclipse wanted to
import sun.awt.image.ImageWatched.Link;
I think that this import is different from what I expect and if I import java.util.Link it gives error.
use
import java.util.LinkedList;
Do you need something like this?
import java.util.LinkedList;
public class LinkTest {
private LinkedList<Object> list = new LinkedList<Object>();
}
Related
I get the following error despite it's exactly one used in examples:
error: type List does not take parameters
List<String> strings_wat = new ArrayList<String>();
Java is version 1.7 and the class is NOT named ArrayList.
You are likely importing java.awt.List.
You should instead import java.util.List, which is a parameterized type.
It seems like you are importing it from java.awt:
import java.awt.List;
and it looks like you want to use the one from java.util:
import java.util.List;
if you are working on Graphical user interface you have to
import java.awt.List instead of import java.util.List
Other then else if you are working on simple code you have to import java.util.List; instead of import java.awt.List
I am getting solved this problem by renaming the class name or file name as in Notepad++.
You Should not take the class names as ArrayList or List.
And you also need to add the following package
import java.util.*;
My Previous class name is List I changed it into the Names.so You have to change the class name.
I get the following error despite it's exactly one used in examples:
error: type List does not take parameters
List<String> strings_wat = new ArrayList<String>();
Java is version 1.7 and the class is NOT named ArrayList.
You are likely importing java.awt.List.
You should instead import java.util.List, which is a parameterized type.
It seems like you are importing it from java.awt:
import java.awt.List;
and it looks like you want to use the one from java.util:
import java.util.List;
if you are working on Graphical user interface you have to
import java.awt.List instead of import java.util.List
Other then else if you are working on simple code you have to import java.util.List; instead of import java.awt.List
I am getting solved this problem by renaming the class name or file name as in Notepad++.
You Should not take the class names as ArrayList or List.
And you also need to add the following package
import java.util.*;
My Previous class name is List I changed it into the Names.so You have to change the class name.
In a JAVA bean that I am working on I want to pass a NotesXspDocument (could use a NotesDocument) to a method which looks like this:
public List<String> getReaders(NotesXspDocument thisXspDoc){
// do some stuff
}
But JAVA does not recognize the NotesXspDocument definition. I have imported the following packages:
import lotus.domino.NotesException;
import lotus.domino.Session;
import lotus.domino.Database;
import lotus.domino.View;
import lotus.domino.Document;
Is there a further package to import to make use the NotesXspDocument?
To elaborate on Jesses answer: in your case you need to do this to work with the XPages version of Document:
import com.ibm.xsp.model.domino.wrapped.DominoDocument;
public List<String> getReaders(DominoDocument thisXspDoc){
// do some stuff
}
NotesXspDocument is an SSJS-only alias; the real class is com.ibm.xsp.model.domino.wrapped.DominoDocument: http://public.dhe.ibm.com/software/dw/lotus/Domino-Designer/JavaDocs/DesignerAPIs/com/ibm/xsp/model/domino/wrapped/DominoDocument.html
I get the following error despite it's exactly one used in examples:
error: type List does not take parameters
List<String> strings_wat = new ArrayList<String>();
Java is version 1.7 and the class is NOT named ArrayList.
You are likely importing java.awt.List.
You should instead import java.util.List, which is a parameterized type.
It seems like you are importing it from java.awt:
import java.awt.List;
and it looks like you want to use the one from java.util:
import java.util.List;
if you are working on Graphical user interface you have to
import java.awt.List instead of import java.util.List
Other then else if you are working on simple code you have to import java.util.List; instead of import java.awt.List
I am getting solved this problem by renaming the class name or file name as in Notepad++.
You Should not take the class names as ArrayList or List.
And you also need to add the following package
import java.util.*;
My Previous class name is List I changed it into the Names.so You have to change the class name.
When I try:
LinkedList<String> stringList = new LinkedList<String>();
I get the following compilation error:
type LinkedList does not take parameters
What am I missing? Can't you do this?
Check to make sure you don't have a compiled class named LinkedList in the same directory. (Especially since "linked list" is a common term, and it is something that people often try to implement as beginners.) This is important if you import your classes using something like import java.util.*;, because the * imports on-demand, so if there is a class with the same name in the package already, then that class is used and the java.util.LinkedList is not imported.
Are you possibly compiling against a JDK 1.4 or earlier? Or do you have your language setting in your build or IDE set to pre-5.0 (so no generics support)?
By the way, the best way to do that is
List<String> stringList = new LinkedList<String>();
Use the interface rather than the implementation wherever possible.
That being said, assuming you're compiling against a JDK 5.0+, have your language settings set to Java 5+ and that is a java.util.LinkedList then your code is perfectly valid.
Don't take the class name as class LinkedList instead you can take class LinkedListDemo and rest of the declaration LinkedList<String> t = new LinkedList<String>(); should be there and it will compile perfectly.
I had a same problem and I figured out that I mistakenly used:
import java.awt.List;
and got the following error message:
"Type List doesn't take paramaters"
Use this instead
import java.util.List;
You have used import java.util.*;
You will not face any issue if you use import java.util.LinkedList;
Type something like this :
import java.util.LinkedList;
class LinkedListDemo {
public static void main(String[] args) {
LinkedList <String> list=new LinkedList <String> ();
}}