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: Eclipse List Type Safety Warning

  1. #1
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,653
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Eclipse List Type Safety Warning

    I have a warning in Eclipse showing up, and I'm not sure why.
    The warning reads:
    Type safety: The expression of type List needs unchecked conversion to conform to List<String>
    I think I understand what the warning is saying, but I do not understand why it is saying it.

    The code in question is here:
    List<String> airports = AirportQuery.getAllAirports("startup");
    Here is the method declaration for AirportQuery.getAllAirports(String)
    public static List<String> getAllAirports(String user) {
    ...
    }

    Now, I don't understand why it feels it needs any conversion to conform to anything. The method clearly returns the exact same type of list I am setting to, so I don't see the problem.
    Is this just a bug in Eclipse or something?
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,039
    My Mood
    Mellow
    Thanks
    184
    Thanked 647 Times in 634 Posts

    Default Re: Eclipse List Type Safety Warning

    What is the actual object type being returned by getAllAirports()?

  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,653
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: Eclipse List Type Safety Warning

    What do you mean? It's just a list of Strings (representing the 3 digit IATA code for a list of airports).

    I'm currently assuming this is a bug, because when I suppressed the warning, Eclipse then started complaining that there is nothing to suppress...
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,039
    My Mood
    Mellow
    Thanks
    184
    Thanked 647 Times in 634 Posts

    Default Re: Eclipse List Type Safety Warning

    What do you mean?
    Show the whole method, and I'll tell/show you what I mean.

    Warnings can always be ignored, and I doubt it's a bug.

  5. #5
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,653
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: Eclipse List Type Safety Warning

    I know warnings can be ignored. But this particular warning could not be annotated as ignore or suppress without the IDE creating a second warning, telling me that the ignore or suppress annotation was unnecessary.
    I don't see why this code will change anything, but here you go regardless (maybe there is something I don't know about and you do):
    public static List<String> getAllAirports(String user) {
    		List<String> ret = new ArrayList<String>();
    		String exactURL = QUERY_LOCATION+USERNAME+user;
    		try {
    			URL url = new URL(exactURL);
    			logger.info("Querying: "+url.getPath());
    			Document document = XMLUtilities.loadXMLFromURL(url);
    			Element element = XMLUtilities.getChildElement(document, "airports");
    			NodeList list = element.getElementsByTagName("airport");
    			for(int i=0;i<list.getLength();i++) {
    				String code = XMLUtilities.getValueOfNode(list.item(i),"code");
    				ret.add(code);
    			}
    		} catch(Exception ex) {
    			logger.throwing("AirportQuery", "getAllAirports", ex);
    			logger.info("Exact URL: "+exactURL);
    		}
    		return ret;
    	}
    Regardless, after fiddling around with my project's build path (there was some issues with it), the warning went away...

    In case anyone else comes across this issue, my project was a Maven Project. Eclipse was claiming the JRE being used was 1.7, but Maven apparently defaults to 1.5. After specifying the source and target version for maven's compiler plugin in the project's pom as 1.7, I removed the JRE from the project's Eclipse Properties, performed a Maven Update, and did a full maven clean and maven install. And poof, the warnings went away...
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  6. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,039
    My Mood
    Mellow
    Thanks
    184
    Thanked 647 Times in 634 Posts

    Default Re: Eclipse List Type Safety Warning

    I don't see why this code will change anything, but here you go regardless (maybe there is something I don't know about and you do)
    There's probably nothing you don't know. Good luck.

Similar Threads

  1. Return type of converting integer to string for linked list
    By jcfor3ver in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 22nd, 2013, 06:37 PM
  2. List of shortcuts key for Eclipse
    By Flash in forum Java JDK & IDE Tutorials
    Replies: 3
    Last Post: July 18th, 2013, 08:40 AM
  3. Replies: 2
    Last Post: April 9th, 2013, 12:39 AM
  4. how to compare 2 different type object list
    By enginco in forum Collections and Generics
    Replies: 3
    Last Post: April 3rd, 2012, 03:45 PM