请问各位java自带类的一些问题
阿神
阿神 2017-04-18 10:47:36
0
3
538
List<List<String>> results = new ArrayList<>();

在java中经常会看到这种写法,定义的类型和new后边的类型不一样,list后还嵌套着list,这个到底是什么意思?

阿神
阿神

闭关修行中......

reply all(3)
小葫芦

Isn’t this just that every element of List is still a List. I didn’t write generics later because they can be omitted.

Peter_Zhu

After Java 7 or 8, generics can be omitted within the <> when instantiating.
As for list<list>, it should be similar to a two-dimensional array.
I wonder if this has been used. Map<string, list<string>> is often used in one-to-many relationships.

迷茫

Both of the two people above answered the question incorrectly. . .
The main question is: 1. Why is the front type List, and the new type at the end is ArrayList? 2. What does it mean that list is nested in list.
To be honest, this question is something you can come into contact with in the first week of learning object-oriented.
The declared type of results is List, but its actual type is ArrayList. ArrayList is the implementation class of List, which means a subclass. The specific type of results cannot be determined during program compilation. Instead, during runtime, the type is dynamically bound based on the actual type of results. This is called polymorphism.
List nested within List means that the elements in this set are still sets one by one.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template