BAEL-2562 New section in Generics article
This commit is contained in:
parent
94917d8755
commit
bde5b5f559
|
@ -1,5 +1,6 @@
|
||||||
package com.baeldung.generics;
|
package com.baeldung.generics;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -28,4 +29,10 @@ public class Generics {
|
||||||
buildings.forEach(Building::paint);
|
buildings.forEach(Building::paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Integer> createList(int a) {
|
||||||
|
List<Integer> list = new ArrayList<>();
|
||||||
|
list.add(a);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.hasItems;
|
import static org.hamcrest.CoreMatchers.hasItems;
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
@ -66,4 +67,12 @@ public class GenericsUnitTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnInt_whenAddedToAGenericIntegerList_thenAListItemCanBeAssignedToAnInt() {
|
||||||
|
int number = 7;
|
||||||
|
List<Integer> list = Generics.createList(number);
|
||||||
|
int otherNumber = list.get(0);
|
||||||
|
assertThat(otherNumber, is(number));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue