Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Unchecked conversion error

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.


    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).


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default 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:
    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.

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Unchecked conversion error

    If you want to store Polynomial objects in your list then the code would be
    LinkedList<Polynomial> list = new LinkedList<Polynomial>();
    Improving the world one idiot at a time!

  5. #5
    Junior Member
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Unchecked conversion error

    Oh nono thats not what im trying to do.

    polynomial_task.jpg

    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.

  6. #6
    Junior Member
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

Similar Threads

  1. HELP! Recompile with -Xlint:unchecked for details?????
    By polozelda in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 7th, 2011, 06:04 AM
  2. Unchecked or Unsafe Operations
    By saxophonemaster in forum Collections and Generics
    Replies: 2
    Last Post: April 12th, 2011, 04:40 AM
  3. Unchecked or Unverified Warning
    By saxophonemaster in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 2nd, 2011, 08:59 PM
  4. Base Conversion
    By Pingu in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 22nd, 2011, 03:15 PM
  5. Explicit Conversion?
    By chronoz13 in forum Java Theory & Questions
    Replies: 3
    Last Post: November 11th, 2009, 11:40 PM