Answer the question
In order to leave comments, you need to log in
Lambda + Wild Card, working with lists?
I want to merge 2 lists and return a new one without changing them using a lambda expression:
interface CombineLists{
List<Number> combine(List<? extends Number> a, List<? extends Number> b);
}
public class SimpleTest {
public static void main(String[] args) {
CombineLists concLists = (a, b) -> {
List<Number> newL = new ArrayList<>();
newL.addAll(a);
newL.addAll(b);
return newL;
};
List<Integer> m1 = Arrays.asList(1,2,3,4);
List<Double> m2 = Arrays.asList(5.0,6.0,7.0,8.0);
System.out.println(concLists.combine(m1,m2));
}
}
interface CombineLists<T extends Number>{
List combine(List<T> a, List<T> b);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question