Type safety / List is a raw type

Viewed 9

Hi i'm getting this warning and I need help on how to fix it, it appears under my combine method which merges two existing lists together, the warning is

Type safety: The expression of type List needs unchecked conversion to conform to List and List is a raw type. References to generic type List should be paramaterized.

For my equals method, my List class says that it's a raw type as well

public class List<T> implements ListInterface<T> {

    private int lastIndex;
    private Object[] elements;

    public List() {
        elements = new Object[10];
        lastIndex = 0;
    }

    public List<T> combine(List<T> list2) {
        List<T> l = new List(); // This is where the warning is underlined
        try {
            for (int i = 1; i <= lastIndex; i++)
                l.add (retrieve (i));
            for (int i = 1; i <= list2.lastIndex; i++)
                l.add (list2.retrieve (i));
        }
        catch (ListException e) {
            System.out.println("Should not occur (Combine)");
        }
        return l;
    }
public boolean equals(Object list) {
        if (list == null) {
         return false;
      }
      List myList = (List)list; // cast to type List // Under each List, it says it is a raw type. References to generic type List<T> should be paramaterized.
      if (myList.getClass() != this.getClass()) {
         return false;
      }
      if (myList.length() != this.length()) {
         return false;
      }
      try {
         for (int pos = 1; pos <= lastIndex; pos++) {
            if (!myList.retrieve(pos).equals(this.retrieve(pos))) {
               return false;
            }
         }
      }
      catch (ListException e) {
         System.out.println("Should not occur");
      }
      return true;
    }

} 


Thank you!

0 Answers
Related