重写equals方法的问题

来源:6-1 学生选课---判断 List 中课程是否存在

不脱发的小Java

2017-09-05 10:35

这里的重写equals方法能不能用系统自动重写

写回答 关注

1回答

  • qq_原点_29
    2017-09-06 22:19:26
    已采纳

    public boolean equals(Object obj) {

    if (this == obj)

    return true;

    if (obj == null)

    return false;

    if (getClass() != obj.getClass())

    return false;

    Student other = (Student) obj;

    if (name == null) {

    if (other.name != null)

    return false;

    } else if (!name.equals(other.name))

    return false;

    return true;

    }

    手写把模版给你自己改


    不脱发的小J...

    非常感谢!

    2017-10-09 19:57:30

    共 1 条回复 >

Java入门第三季

Java中你必须懂得常用技能,不容错过的精彩,快来加入吧

409784 学习 · 4339 问题

查看课程

相似问题