package imooc_collection_map;public class Course {public String id;public String name;public Course(String id, String name) {this.id = id;this.name = name;}public Course() {this.id = id;this.name = name;}public boolean equals(Object obj) {if (this == obj) {return
true;}if (obj == null)return false;if (!(obj instanceof Course))return false;Course course = (Course) obj;if (this.name == null) {if (course.name == null)return true;elsereturn false;} else {if (this.name.equals(course.name))return true;elsereturn false;}}}
Java中某个类的equals方法模板
最新推荐文章于 2021-11-03 15:11:29 发布
本文介绍了一个简单的Java程序,用于创建Course类。该类包括ID和名称属性,并实现了equals方法来比较两个课程对象是否相等。主要关注如何通过名称字段判断课程对象的一致性。
4809

被折叠的 条评论
为什么被折叠?



