BAEL-367 - Simplyfing code
This commit is contained in:
parent
dcb7221d29
commit
75e4fc37ff
|
@ -13,9 +13,8 @@ public class Generics {
|
|||
}
|
||||
|
||||
// definition of a generic method
|
||||
public static <T, G> List<G> fromArrayToList(T[] a, List<G> list, Function<T, G> mapperFunction) {
|
||||
List<T> listWithTypeT = Arrays.stream(a).collect(Collectors.toList());
|
||||
return listWithTypeT.stream().map(mapperFunction)
|
||||
public static <T, G> List<G> fromArrayToList(T[] a, Function<T, G> mapperFunction) {
|
||||
return Arrays.stream(a).map(mapperFunction)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,7 @@ public class GenericsTest {
|
|||
@Test
|
||||
public void givenArrayOfIntegers_thanListOfStringReturnedOK() {
|
||||
Integer[] intArray = {1, 2, 3, 4, 5};
|
||||
List<String> stringList = new ArrayList<>();
|
||||
stringList = Generics.fromArrayToList(intArray, stringList, Object::toString);
|
||||
List<String> stringList = Generics.fromArrayToList(intArray, Object::toString);
|
||||
assertThat(stringList, hasItems("1", "2", "3", "4", "5"));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue