Java: Generics syntax

Viewed 10233

This works to return a list of ints:

public List<Integer> GetIListImpl() {
    return new ArrayList<Integer>();
}

But what if I want to let the caller specify the generic type? Something like this, although syntactically I'm not sure how to do it:

public List<T> GetIListImpl<T>() {
    return new ArrayList<T>();
}

The usage would be:

    List<String> = GetIListImpl<String>();
3 Answers
Related