package com.imooc.collection; /** * 课程类 * * @author sama * */ public class Course { private String id; private String name; public Course(String id, String name) { this.setId(id); this.setName(name); } public Course() { } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public boolean equals(Object object) { if (this == object) { return true; } if (object == null) { return false; } if (!(object instanceof Course)) { return false; } Course course = (Course) object; if (this.getName() == null) { if (course.getName() == null) { return true; } else { return false; } } else { if (this.getName().equals(course.getName())) { return true; } else { return false; } } } }
public void testListContains() { // 取得备选课程序列的第0个元素 Course course = coursesToSelect.get(0); // 打印输出coursesToSelected是否包含course对象 System.out.println("取得课程:" + course.getName()); System.out.println("备选课程中是否包含课程:" + course.getName() + "," + coursesToSelect.contains(course)); System.out.println("请输入课程名称:"); String name = console.next(); System.out.println("!@!!!!!!@#!@"); // 创建一个新的课程对象 Course course2 = new Course(); course2.setName(name); System.out.println("新创建课程:" + course2.getName()); System.out.println("备选课程中是否包含课程:" + course2.getName() + "," + coursesToSelect.contains(course2)); }
没有main方法呀!
Debug的时候运行结果没错