3 ms·
I agree with you. But this code, does not compile List<Integer>[] j=new List<Integer>[10]; and this is a a serious problem. If generics are correctly implemen
by fithisux 11y ago
I agree with you. But this code, does not compile
List<Integer>[] j=new List<Integer>[10];
and this is a a serious problem. If generics are correctly implemented, then it should compile.
- Nutomic 11y agoThat's because List is an interface, not a class. FYI this works in Scala: val j = List(1, 2, 3)
- duaneb 11y agoIt doesn't work for all scala interfaces, and when it is like that, it's often frustrating to find the underlying implementation. But that's beside the point—OP was pointing out that you can't have generic allocation.
- merb 11y agoHowever there are mostly alternatives for Java8 something like that: Collections.singletonList(1, 2, 3) which actually gives a List<Int> by the end it all comes down to syntactic sugar.