?extendsList<LatLng>
means any type that inherits List<LangLng>
.
For example, there is a code like below.
class LatLng {}
class LatLng2 extends LatLng {}
class LatLng3 extends LatLng {}
void print(List<LatLng> l) {}
List<LatLng> l1;
List<LatLng2> l2;
List<LatLng3> l3;
print(l1);
print(l2);
print(l3);
Compiling this code will result in errors in If so, you need to write For this purpose, This conversion allows you to create a function that allows you to Back to the point If you look at the above code, print(l2);
and print(l3);
.
LatLng2
and LatLng3
can be cast after inheriting LatLng
.
However, List<LatLng>
has no inheritance relationship with List<LatLng2>
and List<LatLng3>
.
List
does not care about the inheritance relationship of the element, so List<LatLng>
, List<LatLng2>
and LatLng3>
are different types for p>
print()
for the three types, which can be duplicated and print()
only wants to print out LatLng
whether or not you inherit LatLng
.print()
can be applied generic as below.void print(List<? extends LatLng> l) {}
print(l1);
, print(l2);
and print(l3);
.List <? How is extensionsList <LatLng >>
used?void func(List <? extends List <LatLng >> l) {
// ..
}
List<ArrayList<LatLng>> l1;
List<LinkedList<LatLng>> l2;
List<LinkedList<LatLng>> l3;
func(l1);
func(l2);
func(l3);
l1
, l2
, and l3
are ArrayList
or LinkedList
what you want to do is to save LatLng
in order.
It's just that it's divided into two types of lists depending on the implementation.
In the above code, List <? You can call
.
If func()
whether ArrayList
or LinkedList
because you set it to extentsList <LatLng >>>List <List <LatLng >>
, a call mode error occurs for l1
, l2
, and l3
.
This is because, as I explained earlier, the inheritance relationship of the element is not applied to List
.
© 2024 OneMinuteCode. All rights reserved.