課程
/后端開發(fā)
/Java
/Java入門第二季 升級(jí)版
請(qǐng)問(wèn)equals()方法體的默認(rèn)寫法是什么?謝謝。
2016-01-17
源自:Java入門第二季 升級(jí)版 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_ 提問(wèn)者
不是的,其實(shí)主要就是一個(gè)判斷。
/**
? ? ?* 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,然后再打開他就自動(dòng)生成默認(rèn)equal,你就可以自己參考了
舉報(bào)
課程升級(jí)!以終為始告別枯燥,在開發(fā)和重構(gòu)中體會(huì)Java面向?qū)ο缶幊痰膴W妙
4 回答重寫equals方法的問(wèn)題
2 回答Circle() 方法體要怎么寫
4 回答關(guān)于重寫equals()方法的疑問(wèn)
1 回答關(guān)于equals( )方法重寫的疑問(wèn)?
1 回答無(wú)法生成重寫的equals()方法
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
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
不是的,其實(shí)主要就是一個(gè)判斷。
/**
? ? ?* 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,然后再打開他就自動(dòng)生成默認(rèn)equal,你就可以自己參考了