Search code examples
javajava-6

How can I remove the raw type warning in eclipse from this code?


I currently suppress the nagging from eclipse about the use of raw types in this snippet

@SuppressWarnings({ "rawtypes" })
List doSomething(Integer arg1, ...) {
    ....
}

I am actually returning a raw type List generated from an old version of Hibernate. Is there any way to change this API to return:

List<Object[]>

Do I just cast the List to the above ?


Solution

  • You can usually replace a raw List with a List<?>.

    If you know specifically that the items are Object[], you can simply cast

    List<Object[]> doSomething(Integer arg1, ...) {
        List rawList = ...
        @SuppressWarnings("unchecked")
        List<Object[]> cookedList = (List<Object[]>)rawList;
        return cookedList;
    }