Results 1 to 3 of 3
  1. #1
    TSTONESIX is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

    Default Type mismatch (String)

    I am writing a pretty basic program. In the constructor I am setting a value with data type String to "queue" (line 9) and getting a notification that says "Type mismatch: cannot convert from java.lang.String to String". It's pretty basic code, and am not sure why I am getting an error for this. I would appreciate any help I could get on this.

    Java Code:
    public class LinkedList<String>  {
    	
    	public String name;
    	public ArrayList<ListNode> list;
    	int listSize;
    	
    	
    	public LinkedList(){ //basic constructor (for queue)
    		this.name = "queue"; //give name
    		this.list = null;
    		listSize = 0;
    	}
    }

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,033
    Rep Power
    6

    Default Re: Type mismatch (String)

    The problem is that the LinkedList class is using a real type String as a formal type parameter. That overshadows String so the compiler doesn't recognize String as String.

    If you want to use generics use the following:

    Java Code:
    publc class LinkdeList<T> {
    ...
    }
    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    TSTONESIX is offline Member
    Join Date
    Feb 2013
    Posts
    11
    Rep Power
    0

Similar Threads

  1. Replies: 6
    Last Post: 09-14-2012, 01:33 PM
  2. Replies: 3
    Last Post: 03-26-2012, 01:34 PM
  3. Type Mismatch error
    By and0rsk in forum New To Java
    Replies: 2
    Last Post: 10-10-2010, 12:16 PM
  4. Replies: 6
    Last Post: 02-21-2010, 01:54 AM
  5. Replies: 2
    Last Post: 11-16-2007, 02:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •