This commit is contained in:
Looly
2022-03-27 23:08:45 +08:00
parent 7385fe937d
commit 8177848a47
4 changed files with 10 additions and 2 deletions

View File

@@ -643,7 +643,7 @@ public class IterUtil {
*/
public static Class<?> getElementType(Iterator<?> iterator) {
final Iterator<?> iter2 = new CopiedIter<>(iterator);
if (iter2.hasNext()) {
while (iter2.hasNext()) {
final Object t = iter2.next();
if (null != t) {
return t.getClass();

View File

@@ -90,6 +90,13 @@ public class IterUtilTest {
Assert.assertEquals(expectedMap, testMap);
}
@Test
public void getElementTypeTest(){
List<Integer> integers = Arrays.asList(null, 1);
Class<?> elementType = IterUtil.getElementType(integers);
Assert.assertEquals(Integer.class,elementType);
}
@Data
@AllArgsConstructor
public static class Car {