課程
/后端開發(fā)
/Java
/Java入門第二季 升級版
請問equals()方法體的默認寫法是什么?謝謝。
2016-01-17
源自:Java入門第二季 升級版 9-9
正在回答
package cn.yangxu;
class P{
private int age;
private String name;
public P(int age, String name) {
super();
this.age = age;
this.name = name;
}
public int getAge() {
return age;
public class EqualsClass extends Object{
static int AGE=10;
public boolean equals(P person){
return EqualsClass.AGE==person.getAge();
public static void main(String[] args) {
P person = new P(10,"lisi");
boolean bool = new EqualsClass().equals(person);
System.out.println(bool);
你看看,是這樣的 equals方法主要返回的是bool值
_Jack_Han_ 提問者
不是的,其實主要就是一個判斷。
/**
? ? ?* Returns true if the specified object is equal to this
? ? ?* enum constant.
? ? ?*
? ? ?* @param other the object to be compared for equality with this object.
? ? ?* @return ?true if the specified object is equal to this
? ? ?* ? ? ? ? ?enum constant.
? ? ?*/
? ? public final boolean equals(Object other) {
? ? ? ? return this==other;
? ? }
你直接打開source,然后再打開他就自動生成默認equal,你就可以自己參考了
舉報
課程升級!以終為始告別枯燥,在開發(fā)和重構(gòu)中體會Java面向?qū)ο缶幊痰膴W妙
4 回答重寫equals方法的問題
2 回答Circle() 方法體要怎么寫
4 回答關(guān)于重寫equals()方法的疑問
1 回答關(guān)于equals( )方法重寫的疑問?
2 回答為什么要重寫equals方法?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-01-17
package cn.yangxu;
class P{
private int age;
private String name;
public P(int age, String name) {
super();
this.age = age;
this.name = name;
}
public int getAge() {
return age;
}
}
public class EqualsClass extends Object{
static int AGE=10;
public boolean equals(P person){
return EqualsClass.AGE==person.getAge();
}
public static void main(String[] args) {
P person = new P(10,"lisi");
boolean bool = new EqualsClass().equals(person);
System.out.println(bool);
}
}
你看看,是這樣的 equals方法主要返回的是bool值
2016-01-17
不是的,其實主要就是一個判斷。
/**
? ? ?* Returns true if the specified object is equal to this
? ? ?* enum constant.
? ? ?*
? ? ?* @param other the object to be compared for equality with this object.
? ? ?* @return ?true if the specified object is equal to this
? ? ?* ? ? ? ? ?enum constant.
? ? ?*/
? ? public final boolean equals(Object other) {
? ? ? ? return this==other;
? ? }
2016-01-17
你直接打開source,然后再打開他就自動生成默認equal,你就可以自己參考了