Unchecked conversion error
warning: [unchecked] unchecked conversion
found: java.util.LinkedList
requried: java.util.LinkedList<ListNode>
LinkedList<ListNode> list = new LinkedList<>;
and it has the ^ sign under the word "new"
The above is the warning message i get when i use the command javac.exe -Xlint:unchecked *.java
ListNode = a separate class i wrote in order to create ListNode objects. Basically i am inserting a ListNode object into each index of the LinkedList. However im getting many problems when attempting to run my program and i think it may have something to do with the ListNode class that i wrote.
Code java:
class ListNode
{
private int coefficient;
private int power;
//Constructor
public ListNode(int coefficient, int power)
{
this.coefficient = coefficient;
this.power = power;
}
public ListNode(int degree)
{
power = degree;
}
public void changePower(int power)
{
this.power = power;
}
public void changeCoefficient(int coefficient)
{
this.coefficient = coefficient;
}
//Accessor methods
public int getPower()
{
return power;
}
public int getCoefficient()
{
return coefficient;
}
}
Im not sure if i've provided enough info on the problem. If you want to see the other class where i actually use the ListNode class then you can ask and ill post it up (its quite long however, 250 lines).
Re: Unchecked conversion error
It doesn't have anything to do with your ListNode class. You should copy and paste your error messages, I'd say you've mistyped the one in your original post. What you probably have in your source, if you've only got a warning, is:
Code :
LinkedList<ListNode> list = new LinkedList(); // not <>
The 'unchecked conversion' here is because you've used Generics 'LinkedList<ListNode>' to declare the list reference, and a plain old non-Generics instantiation of a LinkedList. Javac is warning you that your newly-created LinkedList may not contain objects of class ListNode, because you haven't explicitly said it does.
Re: Unchecked conversion error
Polynomial.java:12: warning: [unchecked] unchecked conversion
found : java.util.LinkedList
required: java.util.LinkedList<ListNode>
LinkedList<ListNode> list = new LinkedList();
^
1 warning
Polynomial = the class that i am attempting to use LinkedList and ListNode together in
I have little experience with LinkedLists, but i think they are similar to ArrayLists. I thought that by typing LinkedList<ListNode> i would explicitly say that the linked list would only contain objects of the type ListNode
Re: Unchecked conversion error
If you want to store Polynomial objects in your list then the code would be
Code java:
LinkedList<Polynomial> list = new LinkedList<Polynomial>();
1 Attachment(s)
Re: Unchecked conversion error
Oh nono thats not what im trying to do.
Attachment 681
So basically I create a polynomial object. Inside each polynomial object is just 1 Linked List. Placed on each index of the linked list is an object ListNode (which i had to write a class for). And its the ListNode that stores the data.
Re: Unchecked conversion error
LinkedList<Polynomial> list = new LinkedList<Polynomial>();
I didnt have the underlined part, and thats stopped the warning from appearing whenever i compile. Thnx guys for the help.