为什么Java编译时提示缺少返回值?

2025-03-03 19:28:43
推荐回答(2个)
回答1:

如果你这一个ifif(s.name == this.name && s.location == this.location && s.school == this.school)
return true;没有通过的话 那这个else if(obj instanceof Student) {
Student s = (Student)obj;
if(s.name == this.name && s.location == this.location && s.school == this.school)
return true;
}里面就没有返回值 而你在equals方法结尾也没有给返回值 所以就出现了你说的这用情况

回答2:

逻辑错了,倒数第二个if,里面还有一个return,如:
if(s.name == this.name && s.location == this.location && s.school == this.school)
return true; return true;