equals的用法
通常“==”用于比較基本類型,equals比較的是對象。
但是我現在有個疑問:
class Warehouse
{
public static void main(String args[])
{
Golfball gb1=new Golfball("BrandX","Professional",100);
Golfball gb2=new Golfball("BrandX","Professional",100);
if(gb1.equals(gb2))
System.out.println("equals");
else
System.out.println("not equals");
}
}
輸出的是:not equals
哪位大蝦幫忙解釋一下!!