Im working with the following method:
public void m(List<? extends Object[]> objs){
objs.stream()
.map(oa -> oa[0]) //compile error
//array type expected
.forEach(System.out::println);
}
Why doesn't it work? I thought everything that extends array can be viewed as an array. Actually I can get length
from the array.
There is actually no such class that extends Object[]
; each array has a fixed type and its own class, eg MyClass[].class
You should use a typed method:
public <T> void m(List<T[]> objs){
objs.stream()
.map(oa -> oa[0]) // no compile error
.forEach(System.out::println);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.