From 75e4fc37ff751c3d402801470e1e53714252cdf4 Mon Sep 17 00:00:00 2001 From: slavisa-baeldung Date: Mon, 5 Dec 2016 10:57:34 +0100 Subject: [PATCH] BAEL-367 - Simplyfing code --- core-java/src/main/java/com/baeldung/generics/Generics.java | 5 ++--- .../src/test/java/com/baeldung/generics/GenericsTest.java | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/core-java/src/main/java/com/baeldung/generics/Generics.java b/core-java/src/main/java/com/baeldung/generics/Generics.java index 2b83778f64..28f1da8df9 100644 --- a/core-java/src/main/java/com/baeldung/generics/Generics.java +++ b/core-java/src/main/java/com/baeldung/generics/Generics.java @@ -13,9 +13,8 @@ public class Generics { } // definition of a generic method - public static List fromArrayToList(T[] a, List list, Function mapperFunction) { - List listWithTypeT = Arrays.stream(a).collect(Collectors.toList()); - return listWithTypeT.stream().map(mapperFunction) + public static List fromArrayToList(T[] a, Function mapperFunction) { + return Arrays.stream(a).map(mapperFunction) .collect(Collectors.toList()); } diff --git a/core-java/src/test/java/com/baeldung/generics/GenericsTest.java b/core-java/src/test/java/com/baeldung/generics/GenericsTest.java index 139633d924..5c713ceca4 100644 --- a/core-java/src/test/java/com/baeldung/generics/GenericsTest.java +++ b/core-java/src/test/java/com/baeldung/generics/GenericsTest.java @@ -24,8 +24,7 @@ public class GenericsTest { @Test public void givenArrayOfIntegers_thanListOfStringReturnedOK() { Integer[] intArray = {1, 2, 3, 4, 5}; - List stringList = new ArrayList<>(); - stringList = Generics.fromArrayToList(intArray, stringList, Object::toString); + List stringList = Generics.fromArrayToList(intArray, Object::toString); assertThat(stringList, hasItems("1", "2", "3", "4", "5")); }