Sur*_*nut 3 java generics collections
我想确保Collection只能容纳一个Type.
可以说有这样的方法.
public Collection<Students> getStudents();
Run Code Online (Sandbox Code Playgroud)
可以写下面的代码.
Collection students = getStudents();
students.add(new Book());
Run Code Online (Sandbox Code Playgroud)
Book不延伸Student.现在Collection学生包含一个错误的对象.我怎样才能确保这条线Collection students = getStudents();不可行?
| 归档时间: |
|
| 查看次数: |
262 次 |
| 最近记录: |