I'm attempting to convert the following method:
public List<AliasIp> getStoreAsList(String storeName) {
return new java.util.ArrayList<>(Arrays.asList(mGson.fromJson(getStoreRaw(storeName), AliasIp[].class)));
}
To a generic version similar to:
public <T> List<T> getStoreAsList(String storeName) {
return new java.util.ArrayList<T>(Arrays.asList(mGson.fromJson(getStoreRaw(storeName), T[].class)));
}
But I'm running into troubles with the T[].class which doesn't compile with the error:
"Cannot select from a type variable"
What should the syntax be to avoid that error?
Texpression with definite class (type erasure). Java never leavesTas is. So, when it comes acrossT[], it has no idea, what class should be here. I suggest you follow solution of @Kolesnikovich Dmitry, and pass class as method parameter.Arrays.asListalready returns a list. There is no need to copy it into anArrayList, unless the method guarantees to return the specific typeArrayList, which is not recognizable from its current signature.