I still have a point that I do not understand when working with java generics and lists. I will use here a Class example to keep it simple, but it applies to any generic type.
So: here is the code:
List<Class<? extends Temporal> > x = new ArrayList<>();
x.add(Instant.class);
List<Class<? extends Temporal> > y = x.stream().map(MyClass::w).toList();
private static Class<? extends Temporal> w(Class<? extends Temporal> a){
return a;
}
Here I get an error saying
Provided List<Class<capture of ? extends Temporal>>
And INteliJ propose me to change the type of y to List<? extends Class<? extends Temporal>>
If I use
x.stream()..toList()
or
x.stream().map(TestController::w).collect(Collectors.toList())
The error does not exist any more.
I don’t understand why as the ‘w()’ method return exactly the same Class<? extends Temporal> type as the type of the elements from the initial ‘x’ list.
Thanks for help