Wednesday, 7 August 2013

Generics vs. Method Overloading

Generics vs. Method Overloading

I have 3 methods:
//1 -- check one item
public static <T> void containsAtLeast(String message,
T expectedItem,
Collection<? extends T> found) {
if (!found.contains(expectedItem))
Assert.fail("...");
}
//2 -- check several items
public static <T> void containsAtLeast(String message,
Collection<? extends T> expectedItems,
Collection<T> found) {
for (T exptetedItem : expectedItems)
containsAtLeast(message, exptetedItem, found);
}
//3 -- check several items, without message parameter
public static <T> void containsAtLeast(Collection<? extends T> expectedItems,
Collection<? extends T> found) {
containsAtLeast(null, expectedItems, found);
}
I would expect that the method //3 invoke //2 but it does not, it invoke
method //1. Is there a mistake in what I expect?
*I use sdk 1.7.0_25 and Eclipse 4.3*

No comments:

Post a Comment