ArrayList dates = new ArrayList();
dates.add(new Date());
dates.add(new String());
【B】
ArrayList<Date> dates = new ArrayList<Date>();
dates.add(new Date());
dates.add(new String());
这两个代码片段是否有编译错误?我猜测
add(new String())
这里可能有问题,但不太清楚。
I cannot find the mistake in this arraylist, is the return type of
dates.get()
wrong?ArrayList dates = new ArrayList(); dates.add(new Date()); Date date = dates.get(0);
ArrayList<Date> dates = new ArrayList<Date>();
dates.add(new Date());
Date date = dates.get(0);
If Student is the subtype of the Person, then which are legal?
Person p = new Student(); Student s = new Person(); List<Person> lp = new ArrayList<Student>(); List<Student> ls = new ArrayList<Person>();
我为这些问题苦苦思索了两天,真的需要有人给我一些解释。谢谢提前。
List<Person> lp = new ArrayList<Student>()
,但仍有一些情况可以使用多态性:https://dev59.com/9FTTa4cB1Zd3GeqPqDTn#4959000 - Baumann