List list =newArrayList();
list.add("hello");
list.add("1");
list.add(2);//字符串不能转换为Integer类型所以会出类型转换异常
list.forEach( value ->System.out.println(Integer.parseInt(value +"")));
但是如果规定了泛型那么再添加int类型元素时编译器就会报错,那么这样就可以避免运行时异常的出现,
List<String> list =newArrayList();
list.add("hello");
list.add("1");
list.add(2);//报错
list.forEach( value ->System.out.println(Integer.parseInt(value +"")));