I am writing code that should handle an arbitrary number of doubling lists. However, although I can declare functional parameters like List<List<Double>> , I cannot create the actual instances, since I need to create instances of a specific class, such as ArrayList
I tried
List<? extends List<Double>> inputs = new ArrayList<List<Double>>(); inputs.add(new ArrayList<Double>());
and
List<? extends List<? extends Double>> inputs = new ArrayList<List<Double>>(); inputs.add(new ArrayList<Double>());
but in both cases, I get a compilation error when add() called, saying that the method is not applicable for arguments like ArrayList<Double>
It works
List<List<Double>> inputs = new ArrayList<List<Double>>(); inputs.add((List<Double>) new ArrayList<Double>());
but itโs somehow ugly to use throws in this way. Is there a better approach?
source share