这单元定义的student是student(String id,String name),而为什么老师在添加学生类过程中确是studentlist.add(new student(1+""+"小明"),为什么多添加了一个整型的参数却没有报错呢?
我认为正确的传参方式:
public void testStudentsort()
{
List<student>studentlist= new ArrayList<student>();
studentlist.add(new student("1","小明"));
studentlist.add(new student("2","小红"));
studentlist.add(new student("3","小绿"));
for (student student : studentlist) {
System.out.println("学生"+student.name);
}
}
老师添加学生类的代码
public void testStudentsort()
{
List<student>studentlist= new ArrayList<student>();
studentlist.add(new student(1+"","小明"));
studentlist.add(new student(2+"","小红"));
studentlist.add(new student(3+"","小绿"));
for (student student : studentlist) {
System.out.println("学生"+student.name);
}
}