Skip to content

Commit

Permalink
BAEL-2562 New section in Generics article
Browse files Browse the repository at this point in the history
  • Loading branch information
mikr authored and ashleyfrieze committed Mar 13, 2019
1 parent 94917d8 commit bde5b5f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.baeldung.generics;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
Expand Down Expand Up @@ -28,4 +29,10 @@ public static void paintAllBuildings(List<? extends Building> buildings) {
buildings.forEach(Building::paint);
}

public static List<Integer> createList(int a) {
List<Integer> list = new ArrayList<>();
list.add(a);
return list;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;

import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.fail;

Expand Down Expand Up @@ -66,4 +67,12 @@ public void givenSubTypeOfWildCardBoundedGenericType_thanPaintingOK() {
}
}

@Test
public void givenAnInt_whenAddedToAGenericIntegerList_thenAListItemCanBeAssignedToAnInt() {
int number = 7;
List<Integer> list = Generics.createList(number);
int otherNumber = list.get(0);
assertThat(otherNumber, is(number));
}

}

0 comments on commit bde5b5f

Please sign in to comment.