List<Integer> ints = Arrays.asList(1,2,3,4,5);
List<Double> doubles = Arrays.asList(226.6131 , 7789879.3 );
List<Long> longs = Arrays.asList( 687643643687L , 743926945627L );
List<List<?>> lists = Arrays.asList(ints, doubles , longs); // Type mismatch: cannot convert from List<List<? extends Number&Comparable<?>>> to List<List<?>>
List<List<? extends Number & Comparable<?>>> lists = Arrays.asList(ints, doubles , longs); // Syntax error on token "&", , expected
I am trying to create a List of Lists as the code above shows. First I have 3 lists , each of which stores elements that extends Number implements Comparable. Next I want to put the 3 lists into another List , but I am not able to do this.
List<List<?>> lists = Arrays.asList(ints, doubles , longs);
This line gives compiler error saying cannot convert from List<List<? extends Number&Comparable<?>>> to List<List<?>> .
When I try to modify the type of reference in next line , there is a syntax error.
How do I get the 3 lists above ( ints , doubles and longs ) into another List<> ?
Edit : A related question :
What is correct syntax of declaring a List of Lists of elements that extends Number AND implement Comparable ?
i believe you want something like:
you can use this form for more type safety: