I have searched for this, but unfortunately, I don\'t get the correct answer.
class Helper {
public static T[] toArray(List list) {
I use this simply function. IntelliJ just hates that type cast T[] but it works just fine.
public static T[] fromCollection(Class c, Collection collection) {
return collection.toArray((T[])java.lang.reflect.Array.newInstance(c, collection.size()));
}
And call looks like this:
Collection col = new ArrayList(Arrays.asList(1,2,3,4));
fromCollection(Integer.class, col);