, Class , Object [].
public T[] values(Class<T> cl){
return (T[])map.values().toArray((T[])Array.newInstance(cl,0));
}
You still need to use SuppressdWarning for this code, but it will not throw at runtime. In addition, if you need to implement Collection.values (), you must pass the class to your ctor. Arrays and generics just don't mix, so you should prefer to use collections.
source
share