Results 1 to 3 of 3
  1. #1
    nwboy74 is offline Member
    Join Date
    Oct 2008
    Posts
    45
    Rep Power
    0

    Default Type safety: The expression of type ... needs unchecked conversion to conform to ...

    I have two classes: MakeMeHappy and ServeMe. ServeMe has a method that returns a List<Field>. But in MakeMeHappy, there is a warning that I don't understand how to get rid of (reported on line 11 of MakeMeHappy):
    Type safety: The expression of type List needs unchecked conversion to conform to List<Field>
    I'd like to know how to properly fix it so I am warning-free.

    Java Code:
    package barnacles;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import net.sf.click.control.Field;
    
    public class ServeMe {
      
      private final List<Field> fields = new ArrayList<Field>();
      
      public List<Field> getFields() {
        return this.fields;
      }
    
    }
    Java Code:
    package barnacles;
    
    import java.util.List;
    
    import net.sf.click.control.Field;
    
    public class MakeMeHappy {
      
      public void doSomething() {
        ServeMe server = new ServeMe();
        List<Field> fields = server.getFields();
        // do stuff with the list
      }
    
    }
    I'd prefer to avoid adding @SupressWarnings.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,452
    Rep Power
    20

    Default Re: Type safety: The expression of type ... needs unchecked conversion to conform to

    That's not a compiler message. Is it a warning from your IDE? Also, is this ite actual and complete code that produces that warning, or have you removed some stuff to make it shorter for posting on a forum?

    I didn't see anything there that should generate a 'unchecked conversion' warning, so just to be sure, I created a similar code that doesn't depend on any non-JDK classes, and it compiles without warnings.

    Try compiling from the command line.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    kaydell2 is offline Senior Member
    Join Date
    Dec 2012
    Posts
    106
    Rep Power
    0

    Default Re: Type safety: The expression of type ... needs unchecked conversion to conform to

    I copied and pasted your code into Eclipse. I didn't have the Field class so I made one up. The only warning that I got is that fields isn't used.

    Will you post whole whole files including the Field class and I'll try it again.

Similar Threads

  1. Replies: 6
    Last Post: 09-14-2012, 01:33 PM
  2. java enum : type safety
    By rsai in forum New To Java
    Replies: 2
    Last Post: 07-05-2012, 04:45 AM
  3. Type Conversion Confusion
    By lala in forum New To Java
    Replies: 8
    Last Post: 01-07-2011, 09:59 AM
  4. Type conversion
    By hannes in forum New To Java
    Replies: 2
    Last Post: 12-18-2009, 12:29 PM
  5. runtime type conversion
    By sardare in forum Advanced Java
    Replies: 3
    Last Post: 08-18-2008, 09:51 AM

Posting Permissions

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